0
我重構我所有的代碼來實現,如本文中Scaling Angular Apps描述頂級指令,我不知道如何訪問我的解析值內:接入解決從狀態參數,而不控制器指令
$stateProvider
.state('login', {
url : '/login',
template : '<sr-login-view></sr-login-view>'
})
.state('main', {
url : '/main',
template : '<sr-main-view></sr-main-view>',
resolve : {
directiveConfig : function (Directives) {
return Directives.getConfig('mainScreen');
}
}
});
指令:
angular.module('ElectronClient')
.directive('srMainView', function (directiveConfig //doesn't work) {
return {
restrict : 'E',
require : 'srMainScreen',
scope : {},
templateUrl : 'source/app/directives/main/main_view.html',
controller : function ($scope, directiveConfig //doesn't work) {
//code
},
link : {
post : function (scope, element, attributes, mainViewController) {
}
}
}
});
有一些解決方法呢?具有「頂級」指令的全部要點是不將控制器定義在狀態中,但似乎解析參數僅傳遞給附屬於該狀態的控制器
在'main'狀態下添加控制器,然後將解析'directiveConfig'傳遞給指令隔離範圍。 –
我試圖找到任何其他方式 –
但我想我不得不訴諸於...:p –