我正在尝试将控制器添加到我的Angularjs应用程序中.
这是我第一次在不使用$scope依赖项的情况下进行设置,并使用路由来声明我正在使用的控制器.
在PokemonCtrl没有注册的地方,我做错了什么?另外,如果我在路由中声明控制器这意味着我不必在其他任何地方声明它?
app.js
'use strict';
/**
* @ngdoc overview
* @name pokedexApp
* @description
* # pokedexApp
*
* Main module of the application.
*/
angular
.module('pokedexApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch'
])
.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
controllerAs: 'main'
})
.when('/pokemon', {
templateUrl: 'views/pokemon.html',
controller: 'PokemonCtrl',
controllerAs: 'controller'
})
.otherwise({
redirectTo: '/main'
});
});
Run Code Online (Sandbox Code Playgroud)
pokemonCtrl.js
'use strict';
var pokedexApp = angular.module('pokedexApp', []);
pokedexApp.controller('PokemonCtrl', function() {
var vm = …Run Code Online (Sandbox Code Playgroud)