1

Below is the code. The click event does not work. in ng-click i have included "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'});

  };

}

3
  • 3
    Did you define an ng-controller on the parent element that contains the ng-click. Please post your template file Commented May 16, 2014 at 1:19
  • 1
    The code is incomplete. We can't see your ng-click, the hook of the controller to your module etc. Commented May 16, 2014 at 1:19
  • @OferZelig I tried to post the html template but I could not find a way to post in the description. The html tags disappear when I copy and paste it into the description area Commented May 16, 2014 at 1:25

1 Answer 1

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

No problem, you will enjoy angular :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.