angularjs - How can I use a registered controller in my angular directive? -
i have controller registered this:
mymodule.controller('mycontroller', function ($scope, ...some dependencies...) { ....
using ng-controller="mycontroller"
in html works fine, want utilize controller directive's controller. thing this:
othermodule.directive('mydirective', function() { homecoming { restrict: 'a', replace: true, controller: ??????????, scope: { foo: '=', blah: '=', }, template: '....' } });
i tired putting mycontroller
errors out saying "mycontroller not defined". i'm sure if set mycontroller
in global namespace, work fine, don't want in global namespace. if makes difference, mymodule
defined dependency othermodule
. how can reference controller directive use?
as suggested, tried $controller('mycontroller')
, getting next error:
error: unknown provider: $scopeprovider <- $scope <- mydirectivedirective @ error (<anonymous>) @ http://localhost/resources/angular.js?_=1360613988651:2627:15 @ object.getservice [as get] (http://localhost/resources/angular.js?_=1360613988651:2755:39) @ http://localhost/resources/angular.js?_=1360613988651:2632:45 @ getservice (http://localhost/resources/angular.js?_=1360613988651:2755:39) @ invoke (http://localhost/resources/angular.js?_=1360613988651:2773:13) @ object.instantiate (http://localhost/resources/angular.js?_=1360613988651:2805:23) @ http://localhost/resources/angular.js?_=1360613988651:4621:24 @ othermodule.directive.restrict (http://localhost/resources/app.js?_=1360613988824:862:15) @ object.invoke (http://localhost/resources/angular.js?_=1360613988651:2786:25)
i'm not sure create of error. there more needed create work?
it appears can use:
controller: 'mycontroller'
if controller in same module directive or higher level module composed of module directive in it.
when tried 2 different modules composed app module (one controller , 1 directive), did not work.
angularjs angularjs-directive
No comments:
Post a Comment