[英]Angularjs how to send data from one module to other
我有一個像這樣的模塊
(function() {
var app = angular.module('build', ['ngSanitize', 'uihelper']);
app.controller('buildctrl', ['$scope', function($scope) {
$scope.attributes = {"color": "#efefef", "width": "20px" .... };
...
我的uihelper模塊看起來像這樣。
(function() {
var app = angular.module('uihelper', []);
app.controller('uictrl', ['$scope', function($scope) {
$scope.data = // I want $scope.attributes here
...
我可以訪問模塊2中模塊1中的$scope.attributes
,模塊2會觀察對模塊1中$scope.attributes
的動態更改$scope.attributes
我剛剛開始使用angularjs。 感謝您的幫助。
使用方法創建服務,在需要的地方注入服務
app.service('ConstantsService', function () {
return {
getAttributes: {"color": "#efefef", "width": "20px"}
}
})
app.controller('uictrl', function ($scope, ConstantsService) {
$scope.data = ConstantsService.getAttributes();
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.