javascript - not able to call ng-click in angularjs? -


i newbie , learning angularjs, , stuck @ point , not able figure out wrong doing. have spring restful service , working fine not able call on ng-click. here code snippet

index.jsp

    <body>     <div data-ng-controller="controller1">   <p>create new user:</p>   <p>     name: <input data-ng-model="name" />   </p>   <button data-ng-click="createperson()" >add</button>    <p data-ng-show="newuserid">     user created id: {{newuserid}}   </p> </div> </body> 

my app.js

    var demoapp=angular.module('demoapp',['ngroute']);     demoapp.controller('controller1', function ($scope,$http) {     console.log("in controller");     var urlbase="http://localhost:8080/springangularmaven/";     $http.defaults.headers.post["content-type"] = "application/x-www-form-urlencoded";       $http.createperson = function createperson() {         $http.get('http://localhost:8080/springangularmaven/rest/emp/dummy').         success(function(data) {             $scope.tasks = data;             console.log(data);             $scope.newuserid = data;          });     }; 

output when page loaded console.log("in controller"); executed , when click on button nothing happens....

lookes have typo in controller. need bind createperson function $scope

   var demoapp=angular.module('demoapp',['ngroute']);     demoapp.controller('controller1', function ($scope,$http) {     console.log("in controller");     var urlbase="http://localhost:8080/springangularmaven/";     $http.defaults.headers.post["content-type"] = "application/x-www-form-urlencoded";      //changed $http.createperson $scope.createperson     $scope.createperson = function() {         $http.get('http://localhost:8080/springangularmaven/rest/emp/dummy').         success(function(data) {             $scope.tasks = data;             console.log(data);             $scope.newuserid = data;          });     }; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -