angular
.module('app')
.service('ObjectService', [ObjectService]);
function ObjectService() {
var list = {};
return {
get: function(id){
return list[id];
},
set: function(id, v){
list[id] = v;
}
};
}
// one controller
angular
.module('app')
.controller('OneController', ['$scope', OneController]);
function OneController($scope){
var data = {value: 'test'};
$rootScope.$broadcast('open.notice.editor', data);
}
// other controller
angular
.module('app')
.controller('AnotherController', ['$scope', AnotherController]);
function AnotherController($scope){
$scope.$on('open.notice.editor', function(event, data){
$scope.open(data);
$scope.$emit('notice.editor.opened');
});
}
<div ng-controller="ParentController"> <div ng-controller="ChildOneController"></div> <div ng-controller="ChildTwoController"></div> </div>
// 父控制器
angular
.module('app')
.controller('ParentController', ['$scope', ParentController]);
function ParentController($scope){
// 用于传递数据的变量
$scope.data = null;
}
// 子控制器
angular
.module('app')
.controller('ChildOneController', ['$scope', ChildOneController]);
function ChildOneController($scope){
// 数据设置
$scope.$parent.data = 1;
}
// 子控制器
angular
.module('app')
.controller('ChildTwoController', ['$scope', '$timeout', ChildTwoController]);
function ChildTwoController($scope, $timeout){
$timeout(function(){
// 数据读取
console.log($scope.$parent.data);
}, 1000);
}
// one controller
angular
.module('app')
.controller('OneController', ['$scope', '$window', OneController]);
function OneController($scope, $window){
// 数据设置
$window.data = 1;
}
// other controller
angular
.module('app')
.controller('AnotherController', ['$scope', AnotherController]);
function AnotherController($scope){
// 监听修改
$scope.$watch(function(){
return $window.data;
}, function(n){
$scope.windowData = n;
});
}
<div ng-controller="AppController"> <div id="div-a"></div> </div>
var instance = angular.element(document.getElementById('div-a')).scope();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有