angularjs - 在 angular.service 中使用 Angular 用户界面通知而不是 Controller ?

标签 angularjs angularjs-scope angularjs-module

我可以使用以下语法在 Controller 中使用上面提到的模块,但是当尝试在服务中使用它时它不起作用。

 app.controller('regulationCtrl', function ($scope, $rootScope, $http, $window, $location,Notification) {
           Notification.primary({message: "Some error message", templateUrl: "custom_template.html", scope: $scope}); 
 //THIS CODE WORKS FINE
});

 app.service('fileUploadRegulations',  function ($http,Notification, $rootScope) {
    this.uploadFileToUrl = function (file, country, juridiction, uploadUrl,Notification) {
    Notification.primary({message: "Some error msg:", templateUrl: "custom_template.html", scope: $scope});
 //THIS CODE NOT WORKING
 }
 });

插件官方网址:https://github.com/alexcrack/angular-ui-notification

最佳答案

您不应显示来自服务的UI 通知。您可以使用回调或事件来通知控件“某事”(在您的情况下它似乎是文件上传)已经发生。然后 UI Controller 将显示通知弹出窗口。

关于angularjs - 在 angular.service 中使用 Angular 用户界面通知而不是 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38368594/

相关文章:

javascript - Angularjs - 将 $scope 传递给 Controller

jquery - Angularjs 如何使用来自不同 Controller 的数据附加 ng-repeat

angularjs - 在指令中包装 md-tabs 会产生 "Orphan ngTransclude Directive"错误

javascript - karma.conf.js Uncaught ReferenceError : google no defined

javascript - 将方法从服务调用到 Controller 中

python - Tornado:来自 mysql 的更新数据未显示在由 Tornado 服务的前端中。重启服务器后才显示

angularjs - ng-include 模板变量在 $scope.$watch 上未更改(无按钮触发器)?

javascript - angularJs,$rootScope.$emit()返回一个数据对象

javascript - Angular 模块私有(private)成员

javascript - 访问 json 对象内的集合