This article will share with you the ng-model usage problems in ng-repeat when angular is used by individuals, along with a simple solution, I hope to help you learn about angular. there will be many problems when using ng-model in ng-repeat. some people may encounter problems when they cannot obtain the bound data content, some people change the bound data content together with all the cyclically generated content. I have also encountered the above problems during development, but I cannot solve the problem. I have to briefly introduce how to solve the problem that cannot be obtained.
For example:
Html:
{Pop. pop }} Beijing Shanghai Guangzhou Ceshi
Js:
Script var app = angular. module ('app', []); app. controller ('selectcontroller', function ($ scope) {$ scope. citylist = [{id: 1, pop: "Beijing" },{ id: 1, pop: "Shanghai" },{ id: 1, pop: "Guangzhou"}]; $ scope. cs = function () {console. log ($ scope. p) ;}}) script
This is a simple function. you want to obtain the selected data content of the select statement when you click the Change button, but you will find that only undefined can be obtained in this way, at this time, some people will propose that p can be assigned to an object, and the key: value method is used to save each selection.
$scope.p={};
There is indeed no problem, but there is a new problem that as long as one item is changed, all the content will change together. Is there any better way?
Just a small change
Html:
ceshi
Js:
$scope.cs=function(p){ console.log(p); }
This is just a simple example. if you have any other questions during actual use, you can leave a comment.