javascript - 为什么当我进入 $scope.variabel 时 ng-click 不工作?

标签 javascript angularjs angularjs-directive angularjs-scope

我有问题,我的 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/

相关文章:

javascript - SharePoint 2013 在整个页面加载后添加 JavaScript

javascript - 适用于 Javascript 的 EMVCo TLV 字符串解析器库

javascript - 如何在 rxjs 的 finalize 中正确运行订阅

angularjs - 在 JSFiddle 上运行的简单 AngularJS

javascript - ES6 中的 Getter 和 Setter

javascript - 为什么命名为 : false does not work for me

javascript - AngularJS UI-router 无法使用动态引用加载第二个页面 View

javascript - 添加/删除 'attributes' 基于 Angular 变量或 angularjs 中的评估表达式

angularjs - 在angular js的多选isteven中设置值

javascript - 点击元素未命中angularjs指令链接功能