AngularJS路由不起作用:链接点击时没有事件,没有$routeParams
AngularJS routing is not working: no events on link clicks, no $routeParams
不知何故,我的应用程序在开发过程中停止工作,我真的无法理解它出了什么问题。
我已经删除了所有内容,剩下的唯一代码是:
function handlerControl($scope, $routeParams, $location){
$scope.route = $routeParams;
}
var app = angular.module('Hello', []).config(
function($routeProvider){
$routeProvider.when('/:a/:b', {controller: handlerControl});
}
);
而 html 是
<body ng-app="Hello">
<div ng-controller="handlerControl">
{{route}}
</div>
</body>
省略头部,包括所有内容。
当我去
http://helloday/#/a/b/
我在期望得到 {a: 'a', b: 'b'} 时得到一个空哈希
我做错了什么?
位修改(使其工作) jsFiddle: http://jsfiddle.net/wWDj2/http://jsfiddle.net/wWDj2/
路由要求您使用 ngView,并且指定template
或templateUrl
:
应用代码。
var app = angular.module('myApp', []);
app.config(function($routeProvider) {
$routeProvider.when('/foo/:id', {
controller: 'FooCtrl',
template: '<h1>Foo {{id}}</h1>'
})
.when('/bar/:test', {
controller: 'BarCtrl',
templateUrl: 'bartemplate.html'
})
.otherwise({
controller: 'DefaultCtrl',
template: '<h1>This is the default</h1>'
});
});
app.controller('FooCtrl', function($scope, $routeParams) {
$scope.id = $routeParams.id;
});
app.controller('BarCtrl', function($scope, $routeParams) {
$scope.test = $routeParams.test;
});
app.controller('DefaultCtrl', function($scope){});
主页的标记:
<div ng-app="myApp">
<a href="#/foo/123">Foo 123</a>
<a href="#/bar/blah">Bar Blah</a>
<a href="#">Default route</a>
<hr/>
<div ng-view>
<!-- your processed view will show up here -->
</div>
</div>
相关文章:
- 为什么我的点击事件没有使用 react js 触发
- Bootstrap 3键盘对默认键盘事件没有反应
- Javascript/jQuery-鼠标事件没有在html上触发,添加了动态
- Jquery bind 事件没有响应
- 为什么我的点击事件没有触发
- 为什么我的javascript鼠标事件没有启动
- 为什么asp:LinkButton服务器端事件没有'当clientClick返回true时,t激发
- 谷歌标签管理器点击事件没有冒泡到家长
- 为什么onchange事件没有在第一次更改时启动
- jQuery Mouseenter事件没有启动,它在单击时启动
- 使用WinJs构建的Pivot的幻灯片事件没有'不适用于windows Phone
- jQuery scroll()事件没有't传播
- MSAnimationStart事件没有'我不在IE10上工作
- 谷歌地图的DOM事件没有响应
- 为什么鼠标向上事件没有为子元素触发
- 为什么我的点击事件没有在火狐中注册
- 为什么点击事件没有在关联的 javascript 中注册
- 为什么我的主干集合重置事件没有触发
- 为什么谷歌分析事件没有触发/保存
- 未捕获的类型错误:对象 #<事件> 没有方法“拆分”