search

Home  >  Q&A  >  body text

angular.js - $scope scope issue in AngularJS Controller

controllers.controller('ctrl', ['$scope', function($scope) {
  console.log($scope);//
  $scope.add = function() {
    console.log($scope);//
  };
}]);

Why are the outputs of the above two scopes unequal?

世界只因有你世界只因有你2839 days ago544

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:00:04

    Both outputs point to the $scope bound to the controller. The first one is executed when the controller is loaded, and the second one is executed when the add method is called. The execution time and status of the two are different.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-15 17:00:04

    It is the same object in itself, and the execution content may be different at different times

    reply
    0
  • Cancelreply