3

I need to show info messages in my application. When I do any important operation in any page, a message will be shown as an info message.

This is the page (home page) to show the message

 <body ng-controller="menubarController as ctrl">
        <div id="parent_vertical">
            <div>
                <div  style="float: left;"><img src="<c:url value="images/others/logo-meesters-300x50.png" />"  width="600" height="70" align="top"></div>
                <div ng-show="ctrl.showConfirmationMessage" ><textarea class ="messagesGrid" rows="3" cols="50"> {{ctrl.msg}}   </textarea> </div>
            </div>
    </body>

and this is the messageController

'use strict';

angular.module('mb').controller('menubarController',
            menubarController);

function menubarController($scope, $mdDialog) {
    var ctrl = this;
    ctrl.showConfirmationMessage = false;



    //---------------------------- show sample -------------------------------------------------------------------          
    this.sampleAction = function(name, ev) {
        ctrl.showConfirmationMessage = !ctrl.showConfirmationMessage;
        ctrl.msg = 'Hi ' +name;
        $mdDialog.show($mdDialog.alert().title(name).textContent(
                    'Start learning "' + name + '!' + ctrl.showConfirmationMessage).ok('OK').targetEvent(ev));
    };

    this.showMessage = function (text){
        ctrl.showConfirmationMessage = true;
        ctrl.msg = text;
    }
}

if I called the function showMessage or sampleAction from inside the (home page) everything working

now I want to call this function form another controller first I inject the $controller

.controller(
                'usersListController',
                [
                        'userService',
                        '$uibModal',
                        '$mdDialog',
                        '$scope',
                        '$rootScope',
                        '$timeout',
                        '$controller',
                        function(service, $uibModal, $mdDialog, $scope, $rootScope, $timeout, $controller) {

and this is the controller code

this.editedUser = function (user){
                                ctrl.isSaving = true;

                                 var menubarController = $controller('menubarController');
                                    service
                                            .EditUser(
                                                    user)
                                            .then(
                                                    function handleSuccess(response) {
                                                        $timeout(function(){
                                                             angular.element('#searchForm').triggerHandler('submit');
                                                            }, 1000);

                                                        menubarController.sampleAction('Hi');
                                                    });

                                    this.showEditUserPanel = 0;

                            };

I get the following error

angular.js:12520 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- menubarController

Gopinath Shiva
  • 3,822
  • 5
  • 25
  • 48
Belal Othman
  • 231
  • 3
  • 12
  • Have a look at this [post](http://stackoverflow.com/questions/25417162/how-do-i-inject-a-controller-into-another-controller-in-angularjs). Possible duplicate of the use case scenario you have mentioned in your question. – Gopal Yadav Aug 03 '16 at 10:53

0 Answers0