Angularjs problems encountered when using ng-model in ng-repeat _ AngularJS

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.