0

I'm trying to access a variable from Module-1 inside Module-2... how will I do that?

Example: Module 1

(function () {
    'use strict';

    angular.module('app.Mod1')
        .component('topHeading', {
            templateUrl: 'someTemplate.template.html',
            controller: FirstController,
            controllerAs: 'first'
        });

    function FirstController() {
        /* jshint validthis */
        let vm = this;

        vm.search = 'Sample...';

    }

})();

Example: Module 2

(function () {
    'use strict';

    angular.module('app.Mod2')
        .component('tabSection', {
            templateUrl: 'someTemplate.template.html',
            controller: SecondController,
            controllerAs: 'second'
        });

    function SecondController() {
        /* jshint validthis */
        let vm = this;

        //I WANT TO ACCESS/ASSIGN app.Mod1 vm.search HERE
        vm.search = 'Sample...';

    }

})();

Based on the given code above how will I bind the variable vm.search of "app.Mod1" to "app.Mod2" ???

The scenario is that I have created separate Module for the HEADER and I want to access its variables from another Module and my goal is to do a Two-Way Binding from within another Module... is that possible?

Emz
  • 502
  • 1
  • 3
  • 11
  • possible by using $rootScope but not ideal, this post may help https://stackoverflow.com/questions/18880737/how-do-i-use-rootscope-in-angular-to-store-variables – Tik Feb 04 '19 at 02:00
  • @Tik NEVER use $rootScope – Majesty Feb 04 '19 at 07:32
  • I'm really curious how to do such trick without using $rootScope ... any idea ?? – Emz Feb 04 '19 at 07:36
  • You can try using Angular Service. Also it's a Possible duplicate of https://stackoverflow.com/q/22584342/7192927 – Sukanya Pai Feb 04 '19 at 19:52

0 Answers0