0

I wrote the following AngularJS routing code and it's not working:

/// <reference path="C:\Users\elwany\documents\visual studio 2015\Projects\spaapplication\spaapplication\scripts/angular.js" />

var myApp = angular.module("myApp", ['ngRoute']);
myApp.config(['$routeProvider', 
    function($routeProvider){
        $routeProvider.
        when('/add',{templateurl:'Views/add', controller:'addController'}).
        when('/edit',{templateurl:'Views/edit', controller:'editController'}).
        when('/delete',{templateurl:'Views/delete', controller:'deleteController'}).
        when('/home',{templateurl:'Views/home', controller:'homeController'}).
        otherwise({redirectTo :'/home'});
    }]);
myApp.controller('addController',function($scope){
    $scope.message="in Add view Controller";
});
myApp.controller('editController',function($scope){
    $scope.message="in edit view Controller";
});
myApp.controller('deleteController',function($scope){
    $scope.message="in delete view Controller";
});
myApp.controller('homeController',function($scope){
    $scope.message="in home view Controller";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <title></title>
    <meta charset="utf-8" />
    <link href="Content/bootstrap.css" rel="stylesheet" />
    <script src="scripts/jquery-1.9.0.js"></script>
    <script src="scripts/bootstrap.js"></script>
    <script src="scripts/angular.js"></script>
    <script src="scripts/angular-route.js"></script>
    <script src="demo.js"></script>
</head>
<body>
    <div class="container">
        <nav style="background-color:darkslateblue" role="navigation" class="nav navbar-inverse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#home">home</a></li>
                <li><a href="#add">add</a></li>
                <li><a href="#edit">edit</a></li>
                <li><a href="#delete">delete</a></li>
            </ul>
        </nav>
        <div ng-view>


        </div>
        <h3 style="font-size:small" class="text-center text-info">developed by Mr-Mohammed Elwany</h3>
    </div>
</body>
</html>

And another 4 html <div> in separated 4 HTML pages (add, edit, delete, home) implement this code:

<div class="row jumbotron">
    <h2>{{message}}</h2>
</div>

4
  • Welcome to SO! Can you please give more details of "it's not working"? What do you expect? What errors, if any, you get? Commented Sep 9, 2016 at 8:07
  • What error are you getting?? Commented Sep 9, 2016 at 8:23
  • there are no syntax error in code but it not working Commented Sep 9, 2016 at 8:23
  • may be logical error Commented Sep 9, 2016 at 8:23

1 Answer 1

1

The references should come inside the <body> tag , also you are missing the reference for angular-route

  <head>     
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
 </head>    

DEMO APP

Sign up to request clarification or add additional context in comments.

2 Comments

i wrote that in the second post code and it not worked
<head> <title></title> <meta charset="utf-8" /> <link href="Content/bootstrap.css" rel="stylesheet" /> <script src="scripts/jquery-1.9.0.js"></script> <script src="scripts/bootstrap.js"></script> <script src="scripts/angular.js"></script> <script src="scripts/angular-route.js"></script> <script src="demo.js"></script> </head>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.