marcoslin / angularAMD

Facilitate use of RequireJS in AngularJS
http://marcoslin.github.io/angularAMD
MIT License
734 stars 171 forks source link

navMenu directive tip to require only once #22

Closed dutscher closed 10 years ago

dutscher commented 10 years ago

i've found a way to add the navMenu directive before bootstrapping. this is better because a single require is needed and not in every controller of the app and i've only one directive HTML Tag in my templates.

before in controller files:

head of 'controller / home_ctrl.js'

define(['app', 'directive/navMenu','prettify'], function (app) {
    app.register.controller('HomeController'

head of 'views / home.html'

<div class="masthead" nav-menu></div>

<div class="jumbotron">
    <h1>{{title}}</h1>

head of 'directive/navMenu.js'

define(['app'], function (app) {
    'use strict';
    app.register.directive('navMenu', function () {

after only in bootstrap files:

bottom of app.js

    // add directives
    require(['directive/navMenu'], function(){
        // Bootstrap Angular when DOM is ready
        angularAMD.bootstrap(app);
    });

body of index.html

<div nav-menu></div>

<div class="view-container">
   <div ng-view class="view-frame"></div>
</div>

head of 'directive/navMenu.js'

define(['app'], function (app) {
    'use strict';
    app.directive('navMenu', function () {

no 'app.register' needed if the directive is global.

If this make sense then you can add this :)

greetz from germany!