次のようにコントローラーを登録しました。
myModule.controller('MyController', function ($scope, ...some dependencies...)
{
....
HTML で使用ng-controller="MyController"
するとすべて正常に動作しますが、このコントローラーをディレクティブのコントローラーとして使用したいと考えています。このようなもの:
otherModule.directive('myDirective', function() {
return {
restrict: 'A',
replace: true,
controller: ??????????,
scope: {
foo: '=',
blah: '=',
},
template: '....'
}
});
置くだけで疲れましMyController
たが、「MyController is not defined」とエラーになります。グローバル名前空間に入れるだけでうまくいくと確信MyController
していますが、グローバル名前空間には何も入れたくありません。違いがある場合、myModule
は の依存関係として定義されotherModule
ます。ディレクティブを使用するために、このコントローラーへの参照を取得するにはどうすればよいですか?
提案どおり、試してみ$controller('MyController')
ましたが、次のエラーが表示されます。
Error: Unknown provider: $scopeProvider <- $scope <- myDirectiveDirective
at Error (<anonymous>)
at http://localhost/resources/angular.js?_=1360613988651:2627:15
at Object.getService [as get] (http://localhost/resources/angular.js?_=1360613988651:2755:39)
at http://localhost/resources/angular.js?_=1360613988651:2632:45
at getService (http://localhost/resources/angular.js?_=1360613988651:2755:39)
at invoke (http://localhost/resources/angular.js?_=1360613988651:2773:13)
at Object.instantiate (http://localhost/resources/angular.js?_=1360613988651:2805:23)
at http://localhost/resources/angular.js?_=1360613988651:4621:24
at otherModule.directive.restrict (http://localhost/resources/app.js?_=1360613988824:862:15)
at Object.invoke (http://localhost/resources/angular.js?_=1360613988651:2786:25)
このエラーをどうすればよいかわかりません。これを機能させるためにさらに必要なものはありますか?