我有问题,我的 ngclick 不工作,因为我进入了 $scope.variabel Controller 。
<a id="data_table" ng-click="{{ item.target }}"
我认为当我们调用 {{ item.target }} 但不工作时 target 可以在 ng-click 中使用,有什么解决方案吗?谢谢
这是我的代码:
Controller
$scope.states = {};
$scope.states.activeItem = 'nav1';
$scope.items = [{
id: 'nav1',
target: 'home()',
title: 'Home',
icon: 'fa fa-home fa-3x'
}, {
id: 'nav2',
target: 'data_1()',
title: 'Data 1',
icon: 'fa fa-briefcase fa-3x'
}, {
id: 'nav3',
target: 'data_2()',
title: 'Data 2',
icon: 'fa fa-briefcase fa-3x'
},
{
id: 'nav4',
target: 'data_3()',
title: 'Data 3',
icon: 'fa fa-briefcase fa-3x'
},
{
id: 'nav5',
target: 'data_4()',
title: 'Data 4',
icon: 'fa fa-briefcase fa-3x'
},
{
id: 'nav6',
target: 'data_5()',
title: 'Data 5',
icon: 'fa fa-briefcase fa-3x'
}];
查看
<li ng-repeat="item in items" ng-class="{'active': item.id == states.activeItem}" ng-click="states.activeItem = item.id">
<a id="data_table" ng-click="{{ item.target }}">
<i class="{{ item.icon }}" aria-hidden="true"></i>
<span class="title">{{ item.title }}</span>
<span class="selected"></span>
</a>
</li>
最佳答案
在 Controller 中:将 target: 'home()',
更新为 target: home,
其中 home 是一个函数。
在 View 中:使用 ng-click="item.target()"
关于javascript - 为什么当我进入 $scope.variabel 时 ng-click 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42220674/