0%
EditIf the controller has been attached using the controller as syntax then the controller instance will be assigned to a property on the new scope.
首先,$scope是继承关系,当声明了ng-controller以后,Angular会从上一级controller的$scope或$rootScope构造出新的$scope。
其次,当使用controller as语法时,Angular会构造新的controller实例,并赋予新的$scope。参看下图:
此时原先的controller构造函数已经不能再用于HTML里了。
%23%20Angular%20JS%20-%20controller%20as%0A@%28myblog%29%5Bangular%2C%20javascript%5D%0A%0A%3EIf%20the%20controller%20has%20been%20attached%20using%20the%20controller%20as%20syntax%20then%20the%20controller%20instance%20will%20be%20assigned%20to%20a%20property%20on%20the%20new%20scope.%0A%0A%u9996%u5148%uFF0C%5C%24scope%u662F%u7EE7%u627F%u5173%u7CFB%uFF0C%u5F53%u58F0%u660E%u4E86ng-controller%u4EE5%u540E%uFF0CAngular%u4F1A%u4ECE%u4E0A%u4E00%u7EA7controller%u7684%5C%24scope%u6216%5C%24rootScope%u6784%u9020%u51FA%u65B0%u7684%5C%24scope%u3002%0A%u5176%u6B21%uFF0C%u5F53%u4F7F%u7528controller%20as%u8BED%u6CD5%u65F6%uFF0CAngular%u4F1A%u6784%u9020%u65B0%u7684controller%u5B9E%u4F8B%uFF0C%u5E76%u8D4B%u4E88%u65B0%u7684%5C%24scope%u3002%u53C2%u770B%u4E0B%u56FE%uFF1A%0A%21%5BAlt%20text%7C400x0%5D%28./1503651999428.png%29%21%5BAlt%20text%7C440x0%5D%28./1503652028318.png%29%0A%0A%u6B64%u65F6%u539F%u5148%u7684controller%u6784%u9020%u51FD%u6570%u5DF2%u7ECF%u4E0D%u80FD%u518D%u7528%u4E8EHTML%u91CC%u4E86%u3002