angular.js - How to get the text in the tag in angular?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 17:04:40
0
3
852

For example, the code is as follows:

<body ng-app="app">
    <p ng-controller="myCtr">
        <p>这是要获取的内容</p>
    </p>
</body>

Among them, the text in the p tag is passed through php. I tried ng-bind, ng-model to get, the result is undefined, why not?
How do I get the content of this p tag through angular?
I don’t want to quote jq and get it through js.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
为情所困

What angularjs recommends is to use the controller to obtain the data through $http, and then render it to the template. If you directly use PHP to output to the template, what else does angularjs do?
angularjs has jqLite, you can use angular.element(document.querySelector('p')).text() to achieve your effect, but this is not essentially different from using jQuery.

phpcn_u1582

If you use ng-bind or ng-model only to bind a variable under a scope to it, it will change the value in the tag to undefined. angular.element("#element-id") seems to work

淡淡烟草味

It should be like this

<body ng-app="app">
    <p ng-controller="myCtr">
        <p ng-repeat="item in lists">{{iteam.name}}</p>
    </p>
</body>

在控制器中
angular.module("app",[]);
app.controller("myCtrl",['$scope','$http'],function($scope,$http){
    $http.get("url").then(function(data){
    $scope.lists=data;
    })
})

Get the data transmitted from PHP through the $http service, and then bind it to the view. What I write here is very simple. Generally, the encapsulated interface will be called in the controller, and the specific implementation is usually in the service.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template