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.
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.
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
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.