Javascript $scope与角度的比较
哪一个更好?为什么?Javascript $scope与角度的比较,javascript,angularjs,Javascript,Angularjs,哪一个更好?为什么? (function(){ var app = angular.module('myApp', []); app.controller('MyController', function() { this.guy = obj1; }); app.controller('AnotherController', function ($scope){ $scope.guy = obj2; }); var obj1 = { 'nam
(function(){
var app = angular.module('myApp', []);
app.controller('MyController', function() {
this.guy = obj1;
});
app.controller('AnotherController', function ($scope){
$scope.guy = obj2;
});
var obj1 = {
'name' : 'david',
'title' : 'dude from obj1',
'company' : 'AA',
'doesIt' : 'this uses this'
}, obj2 = {
'name' : 'warren',
'title' : 'dude from obj2',
'company' : 'AA',
'doesIt' : 'this uses scope'
};
})();
我已经看过使用这两种方法的教程。这是偏好吗?只是能否在html属性中使用控制器别名?$scope有什么了不起的地方?我在寻找一个直截了当的答案。谢谢。控制器作为语法的主要优点是,它使html更加清晰:
<div ng-contoller="parentController">
<div ng-contoller="childController">
<!-- you can't say exactly, where test located-->
{{test}}
</div>
</div>
<div ng-contoller="parentController as parent">
<div ng-contoller="childController as child">
<!--it's clear where test-->
{{parent.test}}
</div>
</div>
{{test}}
{{parent.test}
你也可以看到你应该看看约翰·帕帕的风格指南:WayneEllery真棒,这是一个非常有用的链接