Angular the value of the variable in Ng-repeat ng-if in the controller

Source: Internet
Author: User

The essence of this problem is: V-repeat will produce sub-scope, when you take the value in the controller, the equivalent of the parent scope to take sub-scope of the value, because the scope in the angular.js is looked up, so cannot be taken.

The operation process is as follows:

  

The relevant code is as follows:

<Table>    <TR>        <th>Serial number</th><th>Name</th><th>Wages</th><th>Operation</th>    </TR>    <TR>        <TD>{{$index +1}}</TD>        <TD>{{Item.name}}</TD>        <TD><inputname= "Salary"Ng-model= "Salary" /></TD>        <TD><ButtonNg-click= "Myalert ()">Pop-up pay</Button></TD>    </TR></Table><Script>Qrylistctrl. $inject= ['$scope', '$remote']; functionQrylistctrl ($scope, $remote) {$scope. Myalert= function() {alert ($scope. Salary); }    }</Script>

Workaround:

<Table>    <TR>        <th>Serial number</th><th>Name</th><th>Wages</th><th>Operation</th>    </TR>    <TR>        <TD>{{$index +1}}</TD>        <TD>{{Item.name}}</TD>        <TD><inputname= "Salary"Ng-model= "$parent. Salary" /></TD>        <TD><ButtonNg-click= "Myalert ()">Pop-up pay</Button></TD>    </TR></Table>

Principle: The value in scope is passed to the parent scope by $parent attribute.

Angular the value of the variable in Ng-repeat ng-if in the controller

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.