$scope, $rootScope区别

来源:互联网 发布:spring源码 策略模式 编辑:程序博客网 时间:2024/06/06 03:38
scope是html和单个controller之间的桥梁,数据绑定就靠他了

rootscope是各个controller中scope的桥梁


总结:$rootScope.name设置的变量,在所有controller里面都是可以直接用{{$root.name}}来显示的,很强大。那当然也可以赋值给scope.


某个controller.js:


var phonecatApp  = angular.module('phonecatApp',[]);phonecatApp.controller('TestCtrl',['$scope','$rootScope',function($scope,$rootScope) {$rootScope.name = 'this is test';}]);phonecatApp.controller('Test111Ctrl',['$scope','$rootScope',function($scope,$rootScope) {$scope.name = $rootScope.name;}]);


0 0
原创粉丝点击