-1

I have a device service and a device controller. First, time whenever the controller is called, I invoke setter method to set a boolean value. I want to change that value when the logout function is called which is in different service. My Device Service

define([], function () {

    'use strict';

    var DeviceService = [
        "AuthService",
        function (AuthService) {
            var Device_Create = false;
            return {

                setUserCreatePermission :function () {
                    if(AuthService.checkForPermission('Device_Create')){
                        Device_Create = true;
                    }
                },
                getUserCreatePermission : function () {
                    return Device_Create
                }
            }
        }];

    return DeviceService;

})

My Device Controller has a init method which calls the setter method in device service. I have set a scope variable. If it set, it will call the method otherwise not.

define([], function () {
    'use strict';

    var DeviceListCtrl = ["$rootScope", "$scope", "DeviceService",
        function ($rootScope, $scope, DeviceService) {

            //variables

            $scope.deviceList_init = true;
            $scope.Device_Create = false;

            init();

            if(DeviceService.getDeviceCreatePermission()){
                $scope.Device_Create = true;
            }

            function init() {
                if($scope.deviceList_init){
                    DeviceService.setDeviceCreatePermission();
                }
                $scope.deviceList_init = false;

            }

        }]


    return DeviceListCtrl;
});

Can someone help me ? TIA. I am new to this

chan
  • 274
  • 1
  • 5
  • 24

1 Answers1

0

I'm not sure I understood your problem but it seems that you are trying to control two different variables to do the same - one in the controller and other in the service.

If you want to have a variable across different controllers, it should be handled in services/factories.

If you want to notify other controllers that a variable has changed somewhere, you can use $rootScope.$broadcast or $scope.$broadcast depending if it is on the scope or not you need.

sexta13
  • 1,558
  • 1
  • 11
  • 19