【发布时间】:2016-02-24 05:13:05
【问题描述】:
上周早些时候,我发现了一个非常有趣的发现,“角流星”。一个允许使用 AngularJS 框架的 Meteor 包。鉴于我有一些多余的空闲时间,这是假期和所有,我决定试一试。
我已经为我的 Web 应用程序编写了逻辑基础,但仍然存在一个非常非常令人困惑的问题。无论出于何种原因,应用实例化的脚本之外的所有与角度相关的函数都不起作用。
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
}
};
});
结果
- 测试 #1(通过)
- 测试 #2(通过)
- 测试 #3(失败)
- 测试 #4(失败)
【问题讨论】:
标签: javascript angularjs meteor angular-meteor