3: $scope and $rootScope Angularjs

0
Kết quả hình ảnh cho Angular js
#tạo 2 controller là control1 và control2
 var
 test = angular.module('mytest',[]);
 test.controller('control1',function($scope)
{
   $scope.tieude = "thuộc tính tieude nằm trong control1";
});
 test.controller('control2',function($scope)
{
   $scope.tieude = "thuộc tính tieude nằm trong control2";
});
ở view khai báo ng-app và tạo 2 thẻ div như sau:
<body ng-app="mytest">
<div ng-controller="control1">
{{tieude}}
</div>
<div ng-controller="control2"> 
{{tieude}}
</div
</body>
Thêm vào  thẻ ng-model
<body ng-app="mytest">
<div ng-controller="control1">
{{tieude}}
       <input type="text" ng-model="message"/>
        {{message}}
</div>
<div ng-controller="control2"> 
{{tieude}}
        <input type="text" ng-model="message"/>
        {{message}}
</div
</body>
tất cả nội dung khi hiển thị đều giới hạn trong 1 cặp thẻ, và trong từng phần của controller
$rootScope
$rootScope: chứa toàn bộ dữ liệu và phân phối nội dung chung cho tất cả controller sang view.
 var test = angular.module('mytest',[]);
 test.controller('control1',function($scope, $rootScope)
{
   $rootScope.tieude = "thuộc tính tieude nằm trong control1";
});
 test.controller('control2',function($scope)
{
});
Tags

Post a Comment

0Comments
Post a Comment (0)