私は最近この例を見ました。私が指令の中でコントローラを見たのは初めてです。これは普通のことですか?私はあなたがテスト容易化のためのさまざまな分野でこれら二つを保つことになっていたと思った:なぜあなたはAngularJSの指示文にコントローラを配置しますか?
myModule.directive('myComponent', function(mySharedService) {
return {
restrict: 'E',
controller: function($scope, $attrs, mySharedService) {
$scope.$on('handleBroadcast', function() {
$scope.message = 'Directive: ' + mySharedService.message;
});
},
replace: true,
template: '<input>'
};
})
角度ホームページ上の 'tabs'ディレクティブ(タブcomponents.js、コンポーネントの作成を参照してください)は、コントローラを持っている' pane'ディレクティブができるように、タブの$ scopeにアクセスしてください(詳細については、http://stackoverflow.com/questions/11605917/this-vs-scope-in-angularjs-controllers/14168699#14168699を参照してください)。 「[指令のコントローラとリンク関数の違い]」も参照してください(http://stackoverflow.com/questions/12546945/difference-between-the-controller-and-link-functions-when-defining-an-angula/12570008# 12570008)。 –