AngularJS routing does not work: there are no events on link clicks, no $ routeParams

Somehow, my application stopped working during development, and I really can’t understand what’s wrong with it.

I deleted everything, only the following code remained:

function handlerControl($scope, $routeParams, $location){ $scope.route = $routeParams; } var app = angular.module('Hello', []).config( function($routeProvider){ $routeProvider.when('/:a/:b', {controller: handlerControl}); } ); 

and html

 <body ng-app="Hello"> <div ng-controller="handlerControl"> {{route}} </div> </body> 

lowering the head with the inclusion of everything.

When will I go to

 http://helloday/#/a/b/ 

I get an empty hash, expecting to get {a: 'a', b: 'b'}

What am I doing wrong?

Bit changed (to make it work) jsFiddle: http://jsfiddle.net/wWDj2/ http://jsfiddle.net/wWDj2/

+4
source share
1 answer

For routing, you need to use ngView and specify either template or templateUrl :

Application code.

 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){}); 

Homepage layout:

 <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> 
+6
source

All Articles