'this' vs $scope in AngularJS controllers

后端 未结 7 1488
逝去的感伤
逝去的感伤 2020-11-21 05:18

In the \"Create Components\" section of AngularJS\'s homepage, there is this example:

controller: function($scope, $element) {
  var panes = $scope.panes = [         


        
7条回答
  •  臣服心动
    2020-11-21 05:25

    I recommend you to read the following post: AngularJS: "Controller as" or "$scope"?

    It describes very well the advantages of using "Controller as" to expose variables over "$scope".

    I know you asked specifically about methods and not variables, but I think that it's better to stick to one technique and be consistent with it.

    So for my opinion, because of the variables issue discussed in the post, it's better to just use the "Controller as" technique and also apply it to the methods.

提交回复
热议问题