Giter Site home page Giter Site logo

Comments (3)

bfattori avatar bfattori commented on May 13, 2024

When you say directive, and what your code looks like here, indicates to me that you're using Angular. If so, you should look at their Angular examples. I started with that and converted it to load the state and container into the scope. Then I compile the directive with the scope. This is much better than re-initializing Angular each time. For the AngularComponent piece, I have this:

var AngularModuleComponent = function( container, state ) {
    // Get the Angular and Module injectors, the latter is required so
    // that the $compile method can find the Angular components in those modules.
    var $injector = angular.injector(['ng', 'MyApp']),
        $compile = $injector.get('$compile'),
        $rootScope = $injector.get('$rootScope');

    // The template is super-simple... it just invokes the directive.
    var html = "<" + state.directive + "></" + state.directive + ">",
        element = container.getElement();

    // Compile the DOM to initialize the directive. The Golden Layout container
    // and state are passed on the scope into the directive.
    var scope = $rootScope.$new();
    scope.container = container;
    scope.state = state;
    element.html($compile(html)(scope));
};

This avoids bootstrapping Angular for each component, also allowing you to specify your ng-app in the body element if you want. You'll need to compile your Angular templates using something like grunt-angular-templates ahead of time. Then you can set up one of your components like so:

angular.module('MyApp')
        .controller('LoginController', LoginController)
        .directive('login', ['$templateCache', function($templateCache) {
            return {
                restrict: 'E',
                replace: true,
                template: function() {
                    return $templateCache.get('wwwroot/js/templates/login.html');
                },
                controller: LoginController
            }
        }]);

Hopefully this helps you out!

from golden-layout.

prashantkhandelwal avatar prashantkhandelwal commented on May 13, 2024

Thanks @bfattori I will give this a try.

from golden-layout.

prashantkhandelwal avatar prashantkhandelwal commented on May 13, 2024

Thanks @bfattori. Your solution worked. I have to tweaked the module as I have implemented main module a bit differently. But rest everything went well. :)

from golden-layout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.