Sunday, 2 April 2017

What is the common problem with using Controller Aliases ?


Common problem occurred using Alias (Unavailability of this variable inside inner funtions) app.controller("controller1", function ($http) {
   $http.get("MyService/GetEmployee").then( function(response) {
      this.empData = response.data;
   })
});

Solution (Use another variable and assign this object outside the inner function and use it)

app.controller("controller1", function ($http) {
   var vm = this;
   $http.get("MyService/GetEmployee").then( function(response) {
      vm.empData = response.data;
   })
});

No comments:

Post a Comment

Note: only a member of this blog may post a comment.