我正在尝试为此 URL http://crm.dev/accounts
触发一个 Controller ,在此示例中我只是为 Controller 使用了一个匿名函数,但内部的警报不会被触发。我不明白为什么,我猜我错过了什么愚蠢的东西?
我不想使用模板或 View ,我只需要触发我的 Controller 。
请注意,我已经设置了 $locationProvider.html5Mode(true);
。
'use strict';
angular.module('crm', [
'ngSanitize',
'ngRoute',
'angularMoment',
'ui.bootstrap',
'ui.select',
'ui.bootstrap.datetimepicker'
]);
angular.module('crm').config(function(uiSelectConfig) {
uiSelectConfig.theme = 'bootstrap';
});
angular.module('crm').constant('angularMomentConfig', {
preprocess: 'utc',
timezone: 'Europe/Berlin'
});
angular.module('crm').config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
$routeProvider.
when('/accounts', {
controller: function($scope) {
alert('TEST');
}
}).
otherwise({
redirectTo: '/'
});
// enable html5Mode for pushstate ('#'-less URLs)
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
}]);
最佳答案
你需要一个
<ng-view></ng-view>
在你的主模板中,否则路由系统将无法工作
关于javascript - 为什么 AngularJS 路由器不触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29086299/