Javascript 流星角指令

Javascript 流星角指令,javascript,angularjs,meteor,angular-meteor,Javascript,Angularjs,Meteor,Angular Meteor,上周早些时候,我偶然发现了一个非常有趣的发现,“角流星”。允许使用AngularJS框架的Meteor包。考虑到我有一些多余的空闲时间,比如假期等等,我决定尝试一下 我已经为我的web应用程序编写了逻辑基础,但仍然存在一个非常令人困惑的问题。无论出于何种原因,脚本之外与应用程序实例化相关的所有角度函数都不起作用 client/index.html client/app/shared/layout/directive.js 结果 测试#1(通过) 测试#2(通过) 测试#3(失败) 测试4(失败

上周早些时候,我偶然发现了一个非常有趣的发现,“角流星”。允许使用AngularJS框架的Meteor包。考虑到我有一些多余的空闲时间,比如假期等等,我决定尝试一下

我已经为我的web应用程序编写了逻辑基础,但仍然存在一个非常令人困惑的问题。无论出于何种原因,脚本之外与应用程序实例化相关的所有角度函数都不起作用

client/index.html

client/app/shared/layout/directive.js

结果

  • 测试#1(通过)
  • 测试#2(通过)
  • 测试#3(失败)
  • 测试4(失败)

我把我的项目搁置到今天早些时候,当时我决定尝试一些新的东西。我检查了脚本的加载顺序,意识到模块是在指令和控制器之后加载的

我通过将主模块移动到/lib子目录中解决了这个问题

<body ng-app="aboutjn"
      ng-controller="mainCtrl">
    <stdLayout></stdLayout>
</body>
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
    }]);
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
            }
        };
    });