无法在ng-repeat项目中访问ng-click事件

时间:2016-11-15 13:39:59

标签: javascript html angularjs

我正在尝试切换表divng-show的可见性。单击每个ng-repeat元素时应触发该事件,但事实并非如此。

我的代码如下:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="ApiTestApp">
<head>
    <title></title>
    <link href="lib/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <script src="lib/jquery-1.12.1.min.js"></script>
    <script src="lib/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="lib/angular.js"></script>
    <script src="view-model/tester.js"></script>
    <script>
        (function (app) {
            app.controller('TesterController', TesterController);
        })(angular.module('ApiTestApp', []));
    </script>
</head>
<body ng-controller="TesterController">
    <div class="dropdown">
        <button class="btn btn-default dropdown-toggle" type="button" id="drtitles" 
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
            Titles
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" aria-labelledby="drtitles">
            <li ng-repeat="shura in shurot">
               <a ng-click="authors.show=true" >{{shura.title}}</a>
            </li>
        </ul>
    </div>
    <br />
    <table class="table table-bordered" ng-show="authors.show">
        <thead><tr><td>Authors</td></tr></thead>
        <tbody><tr><td></td></tr></tbody>
    </table>
</body>
</html>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

TesterController在哪里定义?我的猜测是你在那里做错了什么。您的模板按照我的意图工作,控制器定义为......

    $scope.shurot = [
        { title: "Title 1" },
        { title: "Title 2" },
        { title: "Title 3" }
    ]

    $scope.auhors = {
        show: false
    }