typescript - AngularJS Unknown provider - For Controllers -
i know there lot of these question, specific. using typescript angularjs. want variable multimediacontroller multimediaalbumcontroller. getting "[$injector:unpr] unknown provider: multimediacontrollerprovider <- multimediacontroller <- multimediaalbumcontroller". how can prevent it?
multimediaalbumcontroller
export class multimediaalbumcontroller{ $scope; albums : albumdto[]; $popupmanager; $state; $element; mutlimediacontroller; static $inject = ['$injector', '$scope', '$stateparams', '$state', '$popupmanager', '$element','multimediacontroller'] constructor( $injector : ng.auto.iinjectorservice, $scope, $stateparams, $state, $popupmanager, $element, mutlimediacontroller: multimediacontroller ) { super(); $injector.invoke(this.init, this, {$scope}); this.$scope = $scope; this.$element = $element; this.$state = $state; this.$popupmanager = $popupmanager; this.mutlimediacontroller = multimediacontroller; this.albums = mutlimediacontroller.albums; }
as can see have declared multimediacontroller, write in $inject. bug? :/
you should not inject
1 controller rather should using service\factory
.
however scope
of mutlimediacontroller
, need inject $controller
service of angularjs. can ike :
static $inject = ['$injector', '$scope', '$stateparams', '$state', '$popupmanager', '$element','$controller'] constructor( $injector: ng.auto.iinjectorservice, $scope, $stateparams, $state, $popupmanager, $element, $controller ) { super(); $injector.invoke(this.init, this, {$scope}); this.$scope = $scope; this.$element = $element; this.$state = $state; this.$popupmanager = $popupmanager; var mutlimediacontroller = $controller('multimediacontroller', {this.$scope: $scope}); mutlimediacontroller.somefunction();// function of multimediacontroller this.albums = mutlimediacontroller.albums; }
but suggest making service/factory access common data.
like :
myapp.service('myservice', function() { var text = ''; this.getvalue = function () { return text; } this.setvalue = function (data) { return text = data; } }); //inside controller myapp.controller('myctrl', function myctrl($scope, myservice) { myservice.setvalue ("data service"); $scope.message = myservice.getvalue(); });
Comments
Post a Comment