老技术栈,希望有人可以伸出援助之手。我正在尝试将 mathjs 库包装在 $scope 中并遇到问题。
我的路线(angular-ui-router,angularjs):
.state('statistics', {
url: '/statistics/{jobTitle}',
views: {
'content': {
template: '<statistics></statistics>',
controller: function($scope, mathController, simpleObj){
console.log(simpleObj);
console.log(mathController);
$scope.$on('ocLazyLoad.fileLoaded', function(e, module) {
console.log('module loaded', module);
console.log(mathController);
});
$scope.mathController = mathController;
$scope.simpleObj = simpleObj;
}
},
'footer': {
template: '<footer></footer>'
},
},
resolve: { // Any property in resolve should return a promise and is executed before the view is loaded
mathController: ['$ocLazyLoad', function($ocLazyLoad) {
// you can lazy load files for an existing module
return $ocLazyLoad.load('/assets/js/math.min.js')
}],
simpleObj: function(){
return {value: 'simple!'};
},
}
现在,console.log(mathController) 记录未定义,而 simpleObj 返回未定义。谁能解释一下?我该如何解决?这不是异步加载的问题,因为即使我在事件触发后登录控制台,它仍然是未定义的。我的假设是我应该能够在控制台中看到该功能?