ich den neuen Dienst in meinen Controller gespritzt habe, aber es sagt immer unbekannt AnbieterAngularJS, nach dem Dienst Injektion, meldet es noch unbekannter Anbieter
mein Code: Exportservice:
class AlertService {
constructor($rootScope,$injector) {
this.rootScope = $rootScope;
this.injector = $injector;
}
showAlert(alertTitle='Alert',alertBody='') {
this.injector.get('$uibModal').open({
template: '<header><div class="alert-header"><h1>' + alertTitle + '</h1></div><div class="alert-close" ng-click="ok()"><i class="icon icon--close" aria-hidden="true"></i></div></header>'
+ '<section class="content-section content-section-alert"><p>' + alertBody + '</p></section>'
+ '<footer><button class="btn btn-primary" ng-click="ok()">ok</button>',
controller: function($scope, $uibModalInstance,$rootScope) {
$rootScope.ok = function() {
$uibModalInstance.dismiss('cancel');
};
},
windowClass: 'alert-modal'
});
}
}
AlertService.$inject = ['$rootScope','$injector'];
export default angular.module('services.alertService', [])
.service('alertService', AlertService)
.name;
die injizieren Service in der Steuerung:
export default class StartController {
constructor($scope, alertService, $location){
this.alertService = alertService
this.scope = $scope
this.location = $location
this.watchUrl()
}
watchUrl() {
let url = this.location.url()
if(url.indexOf('start') == -1)
return
this.alertService.showAlert('alert','some error')
}
}
StartController.$inject = ['$scope', 'alertService', '$location'];
es würde immer melden unbekannt Anbieter:
Unknown provider: tProvider <- t
wenn ich die alertService
zu alert()
ändern, dann funktioniert es
, was der Grund sein? Dank
Vermutlich liegt das Problem in 'AlertService'. Wie sieht es aus? – Phil
In welchem Modul befindet sich Ihr Controller? Ist dieses Modul von 'services.alertService' abhängig? – Phil
@Phil, Ich habe den Alarm eingefügtService-Code –