繁体   English   中英

AngularJS范围作为HTML属性值

[英]AngularJS Scope as HTML attribute value

我正在尝试使用AngularJS $ scope作为HTML属性而不是可见文本。

main.js

var myApp = angular.module('myApp');

myApp.controller("buttonCtrl", ['$scope', function($scope){

$scope.johnny = [
    {quote: 'Anything for My Princess', controller: 'Princess'}
];

}]);

page1.html

<button ng-repeat="button in johnny" 
    ng-class="dynamic" 
    class="topcoat-button"
    ng-controller="{{button.controller}}"   <---- this is what does not work 
    ng-click="play()">
    {{button.quote}}
</button>

如何解决此问题,以便可以将这些变量添加为属性值。

谢谢

这样做时Angular.js有点奇怪,但这应该可行。 另外,您使用的ng-repeat错误,但在下面已修复。

<button ng-repeat="johnny in buttons" 
    ng-class="dynamic" 
    class="topcoat-button"
    ng-controller="this.johnny.controller"
    ng-click="play()">
    {{johnny.quote}}
</button>

暂无
暂无

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

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