ng-click在AngularJS中不起作用

时间:2014-05-16 01:15:21

标签: angularjs

以下是代码。点击事件不起作用。在ng-click中我已经包含了“insertTom()”。

GOOGLE CDN:https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js

  var myAppModule = angular.module('myApp', []);

  var students = [{name:'Mary Contrary', id:'1'},

                  {name:'Jack Sprat', id:'2'},

                   {name:'Jill Hill', id:'3'}];

  function StudentListController($scope) {

      $scope.students = students;

      $scope.insertTom = function () {

      $scope.students.splice(1, 0, {name:'Tom Thumb', id:'4'});

  };

}

1 个答案:

答案 0 :(得分:1)

<div ng-controller="StudentListController">
  <!-- content -->
  <button type="button" ng-click="insertTom()">Insert</button>
</div>

没问题,你会喜欢棱角分明的:)