简体   繁体   English

AngularJS ng-repeat主体不替代md-button ng-click属性中的$ index

[英]AngularJS ng-repeat body does not substitute $index in md-button ng-click attribute

I have the following template defined: 我定义了以下模板:

 <div ng-app="WebApp" ng-controller="PortfolioCtrl" ng-cloak layout="row" layout-align="center center" style="margin-top: 10px"> <md-content layout="row" layout-wrap style="width: 580px"> <div flex-xs flex-gt-xs="50" layout="row" ng-repeat="property in portfolio track by property.uuid"> <md-card md-theme="default" md-theme-watch="" style="width: 280px"> <md-card-title> <md-card-title-text> <span class="md-headline">{{property.yield}}%</span> <span class="md-subhead">{{property.address[0]}}</span> <span ng-if="property.address.length > 1" class="md-subhead">{{property.address[1]}}</span> <span ng-if="property.address.length > 2" class="md-subhead">{{property.address[2]}}</span> </md-card-title-text> <md-card-title-media> <!-- <div ng-if="property.photos.length > 0" class="md-media-sm card-media"> <img src="{{property.photos[0]}}" style="width: 75px; height: 85px" /> </div> --> </md-card-title-media> </md-card-title> <div style="display: none">{{$index}}</div> <div id="property_$index" style="display: none">{{property.uuid}}</div> <md-card-actions layout="row" layout-align="end center"> <md-button class="md-primary" ng-click="viewProperty( $index )">VIEW</md-button> <md-button class="md-primary" ng-click="uploadPhoto( $index )">UPLOAD PHOTOS</md-button> </md-card-actions> </md-card> </div> </md-content> </div> 

Looking at the below browser developer output, the $index specifications substitute correctly in the tag: 查看下面的浏览器开发人员输出,$ index规范在标记中正确替换:

 <div style="display: none">{{$index}}</div> 

But within the ng-click attributes in the buttons and in this DIV id: 但是在按钮和此DIV ID的ng-click属性中:

 <div id="property_$index" style="display: none">{{property.uuid}}</div> 

, they do not substitute. ,它们不能替代。 If I surround these $index specifications with {{ and }} I get an angular syntax error: 如果将这些$ index规范用{{和}}包围,则会出现角度语法错误: 在此处输入图片说明

Tracking by $index doesn't work either. 通过$ index跟踪也不起作用。 What is the problem, please? 请问是什么问题?

在此处输入图片说明

I was using {{}} inappropriately. 我不适当地使用{{}}。 In ng-click() you don't use them, but in other locations, such as tag attributes, they need to be used. ng-click()您无需使用它们,但在其他位置(例如标签属性),则需要使用它们。

Correct use: 正确使用:

<md-card md-theme="default" md-theme-watch="" flex-direction="column" ng-click="viewProperty( $index )" style="width: 158px">

And: 和:

<div id="property_{{$index}}" style="display: none">{{property.uuid}}</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM