Question

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'});

  };

}

Was it helpful?

Solution

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

No problem, you will enjoy angular :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top