Praveen Krishna P Praveen Krishna P - 1 year ago 137
AngularJS Question

$routeProvider, injection in angularjs, not able to identify the error

On clicking register, just the url changes and not taked to register.html or displayed the content


html file

<!DOCTYPE html>
<script src = ""></script>
<script src = ""></script>
<script src="Script/Scc.js"></script>
<body ng-app="sampleApp">
First Name<input type="text" ng-model="reg.firstName" /><br />
Last Name<input type="text" ng-model="reg.lastName" /> <br />
<a href="#Register"> Register </a>


var sampleApp = angular.module('sampleApp', ['ngRoute']);
function ($routeProvider) {
when('/#Register', {
templateUrl: '/register.html',
controller: 'registerController'
sampleApp.controller('registerController', function ($scope,$route) {
var reg = {
firstName: 'Mmm',
lastName: 'Nnn',
$scope.reg = reg;


<!DOCTYPE html>
<html xmlns="">
First Name is{{ reg.firstName }}<br />
Last Name is {{reg.lastName}}

not able to retrieve the textbox content and display it in register.html...

Answer Source

You need ng-view directive in your html to indicate where the template should be injected. Something like <div ng-view></div>.

And your register.html shouldn't be a full HTML document, it should be a partial template contaning just the data that needs to be injected.

And you don't need the # in route:

when('/Register', {
    templateUrl: '/register.html',
    controller: 'registerController'

Make sure the path to template is correct.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download