Directives in meteor-angular

- 1 answer

Ad

Earlier last week I came across a very intriguing find, 'angular-meteor'. A Meteor package that allows usage of the AngularJS framework. Given I had some excess freetime, it being the holidays and all, I decided to give it a stab.

I've written the logical base for my web app, but a very, very confusing problem persists. For whatever reason, all angular related functions outside of the script with the app's instantiation, don't work.

client/index.html

<body ng-app="aboutjn"
      ng-controller="mainCtrl">
    <stdLayout></stdLayout>
</body>

client/app/module.js

angular.module('aboutjn',['angular-meteor']); // #  initialize angular module

/*
    *   ANGULAR-METEOR CHEAT-SHEET
    *   @ newbie guide

    $root.currentUser =>
 */

angular.module('aboutjn')
    .controller('mainCtrl', ['$scope', '$reactive', function ($scope, $reactive) {

        $reactive(this).attach($scope);
            // create reactive context within scope

        $scope.helpers({
            posts: function() {
                return Posts.find({}, {sort: {createdAt: -1}})
            }
        }); // meteor style helper to instantiate scope context

        console.log('test #1'); // # passed
    }]);

client/app/shared/layout/directive.js

console.log('test #2'); // # passed

var module = angular.module('aboutjn');

    module.run(function() {
        console.log('test #3'); // # failed
    });
    module.directive('std-layout', function() {
        return {
            restrict: 'E',
            templateUrl: 'client/app/shared/layout/view/stdLayout.html',
            controllerAs: 'layoutCtrl',
            controller: function () {
                console.log('test #4'); // # failed
            }
        };
    });

Results

  • test #1 (passed)
  • test #2 (passed)
  • test #3 (failed)
  • test #4 (failed)
Ad

Answer

Ad

I put my project on hold until earlier today, when I decided to try something new. I checked to see the load order of my scripts, and realized the module was being loaded AFTER my directives and controllers.

I solved this by moving my main module into a /lib subdirectory.

Ad
source: stackoverflow.com
Ad