$scope vs var in AngularJS

后端 未结 5 1837
暖寄归人
暖寄归人 2020-12-05 17:38

I\'ve been using var and $scope.varname and both work fine in AngularJS. I was wondering if there was a difference between the two functionally, and what best practice was i

5条回答
  •  攒了一身酷
    2020-12-05 17:57

    1 - $scope, is the glue between your controller and your view/model , when you are defining a variable/function to the $scope of a controller, your whole view , which this controller controls it ! , can see that variable/function . Where a pure variable just works in that controller , not even the view of that controller!

    2- Every thing that has been defined to the $scope , is manupulatable from the outside of the controller , throughout the Directives , Services , your html view ... , while a pure variable is NOT;

提交回复
热议问题