如何使用 angularjs 控制器更改自定义属性值?
how to change the custom attribute value using angularjs controller?
我在我的应用程序中使用了 material 设计 class。
<div flex="30" flex-sm="100" ng-repeat="shortListLoad in user.shortListLoads">
<md-button class="md-icon-button md-primary" aria-label="Settings" ng-click="checkShortList(shortListLoad.id)">
<md-icon md-font-icon='icon-favorite' style='color:red'></md-icon>
</md-button>
</div>
我需要在调用 checkShortList() 函数时将 "md-font-icon" 属性值更改为 'icon-favorite-outline'在控制器中。
如何做到这一点请在 angularjs 而不是 jquery 中提出最佳方法???
在控制器方法 checkShortList
中设置 flag
值。
在每个 shortListLoad
对象中保留一个标志。
//initially
angular.forEach(user.shortListLoads,function(res){
res.flag = true;
});
$scope.checkShortList = function(shortListLoad,id){
shortListLoad.flag = false;
}
HTML
<md-button class="md-icon-button md-primary" aria-label="Settings" ng-click="checkShortList(shortListLoad,shortListLoad.id)">
<md-icon md-font-icon="{{shortListLoad.flag ? 'icon-favorite' : 'icon-favorite-outline' }}" style='color:red'></md-icon>
</md-button>
我在我的应用程序中使用了 material 设计 class。
<div flex="30" flex-sm="100" ng-repeat="shortListLoad in user.shortListLoads">
<md-button class="md-icon-button md-primary" aria-label="Settings" ng-click="checkShortList(shortListLoad.id)">
<md-icon md-font-icon='icon-favorite' style='color:red'></md-icon>
</md-button>
</div>
我需要在调用 checkShortList() 函数时将 "md-font-icon" 属性值更改为 'icon-favorite-outline'在控制器中。
如何做到这一点请在 angularjs 而不是 jquery 中提出最佳方法???
在控制器方法 checkShortList
中设置 flag
值。
在每个 shortListLoad
对象中保留一个标志。
//initially
angular.forEach(user.shortListLoads,function(res){
res.flag = true;
});
$scope.checkShortList = function(shortListLoad,id){
shortListLoad.flag = false;
}
HTML
<md-button class="md-icon-button md-primary" aria-label="Settings" ng-click="checkShortList(shortListLoad,shortListLoad.id)">
<md-icon md-font-icon="{{shortListLoad.flag ? 'icon-favorite' : 'icon-favorite-outline' }}" style='color:red'></md-icon>
</md-button>