App.js
var myApp=angular.module('sampleApp', ['ui.router','MainCtrl', 'NerdCtrl',
'NerdService', 'GeekCtrl', 'GeekService','ngMaterial']);
myApp.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'views/login.html'
})
.state('nerd', {
url: '/nerd',
templateUrl: 'views/nerd.html',
//controller: NerdController
})
.state('geek', {
url: '/geek',
templateUrl: 'views/geek.html'
});
$urlRouterProvider.otherwise('/login');
});
我从 AngularJs 样板开始,并尝试将 UI Router 与它一起使用,并且我已经坚持了一段时间了。当我注释掉上面显示的代码行时,它工作正常并且没有出现错误。但是,当我添加 Controller 时,我得到 this module error在控制台中显示“ReferenceError:NerdController 未定义”。我已经定义了 Controller 并添加了 Controller 依赖项,但我不确定我需要做什么。我正在监督这似乎是一个简单的错误。感谢您的帮助!
这是 Controller 文件:
angular.module('NerdCtrl', []).controller('NerdController', function($scope)
{
$scope.tagline = 'Nothing beats a pocket protector!';
});
我的目录结构有问题吗?
最佳答案
更改为: Controller :“NerdController”
var myApp=angular.module('sampleApp', ['ui.router','MainCtrl', 'NerdCtrl',
'NerdService', 'GeekCtrl', 'GeekService','ngMaterial']);
myApp.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'views/login.html'
})
.state('nerd', {
url: '/nerd',
templateUrl: 'views/nerd.html',
controller: "NerdController"
})
.state('geek', {
url: '/geek',
templateUrl: 'views/geek.html'
});
$urlRouterProvider.otherwise('/login');
});
关于angularjs - 将 Controller 添加到 UI Router 状态时,AngularJS 中出现模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48355577/