出力を出力するカスタム ディレクティブをホームページに表示しようとしています。devtools のネットワーク タブで、コントローラーが 2 回読み込まれることを確認しました。
コントローラ:
var homeController = function($log,leaguesFactory){
var self = this;
self.leagues = [];
leaguesFactory.loadLeagues()
.then(function(leagues){
self.leagues = leagues.data.Competition;
});
self.message= 'test message';
};
指令:
var leaguesTabs = function(){
return {
restrict : 'E',
templateUrl : 'app/home/leagues-tabs.tpl.php',
scope: {
leagues: '='
},
controller: 'homeController',
controllerAs: 'homeCtrl'
};
};
ui-router 状態:
$stateProvider
.state('home',{
url : '/',
templateUrl : 'app/home/home.tpl.php',
controller : 'homeController',
controllerAs: 'homeCtrl'
})...
ディレクティブで homeCtrl を使用したいだけですが、状態プロバイダーもそれをロードし、2 回ロードするようです。ディレクティブからコントローラーを削除すると、homeCtrl にアクセスできなくなります。homeCtrl を stateprovider から削除すると、home.tpl.php にアクセスできなくなります。
home.tpl.php:
<div>
<leagues-tabs></leagues-tabs>
</div>
何か案が?