2016-08-23 3 views
0
<h1 ng-controller="mainController as mainCtrl">{{ms}}</h1> 

.controller("mainController",function(){ 
this.ms = "hi"; 
}); 

왜 angularjs에 as을 사용하는 사람들이 있습니까? 내가 주로하는 일은 당신이은 angularjs에서 컨트롤러 사용에 대한 참조로 사용됩니다.

<h1 ng-controller="mainController as mainCtrl">{{mainCtrl.ms}}</h1> 

app.controller("mainController", function() { 
    this.ms = "hi"; 
}); 

더 나은이 here을 설명한다면 당신은 $scope을 주입 할 필요가 없습니다 $ 범위를 주입하고 $scope.ms = 'something'

답변

2

을 할 수 있습니다.

EDIT : AngularJS Official Docs에도 언급되어 있습니다. ngController을 참조하십시오.

+0

이것은 새로운 것입니까? 그것이 바람직한 방법이라면 왜 공식적인 공식 사이트를 사용하지 않는 것이 좋습니까? –

관련 문제