Jab*_*her 4 javascript angularjs
不知何故,我的应用程序在开发过程中停止工作,我真的不知道它有什么问题.
我删除了所有内容,剩下的唯一代码是:
function handlerControl($scope, $routeParams, $location){
$scope.route = $routeParams;
}
var app = angular.module('Hello', []).config(
function($routeProvider){
$routeProvider.when('/:a/:b', {controller: handlerControl});
}
);
Run Code Online (Sandbox Code Playgroud)
和HTML是
<body ng-app="Hello">
<div ng-controller="handlerControl">
{{route}}
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
省略包括一切的头部.
当我去
http://helloday/#/a/b/
Run Code Online (Sandbox Code Playgroud)
我得到一个空哈希,同时期望获得{a:'a',b:'b'}
我做错了什么?
位修改(使其工作)jsFiddle:http://jsfiddle.net/wWDj2/ http://jsfiddle.net/wWDj2/
路由要求您使用ngView,并指定a template或a 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){});
Run Code Online (Sandbox Code Playgroud)
您的主页标记:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4020 次 |
| 最近记录: |