简体   繁体   中英

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.6.6/$injector/modulerr?p0 Still not working please Check my code

i am trying to code this and just Jump form 1 page to another page using routes but doesn't why its not working i search and tricks a lot but still failed please any one?

 index.html <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <title>Angular Js</title> <script type="text/javascript" src="angular.min.js"></script> <script src="controller.js"></script> <script src="angular-route.min.js"></script> </head> <body> <div ng-view></div> </body> </html> 
 ---------- Controler.js var myRoute=angular.module('myApp',['ngRoute']); myRoute.config(function($routeProvider){ $routeProvider .when('/',{ template:'Welcome to Home' }) .when('/NewPage',{ template:'This Is New Page Task' }) otherwise('/',{ redirectTo:'/' }); }); 

The order of references should be,

<script type="text/javascript" src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script src="controller.js"></script>
app.config(function ($routeProvider) {
    $routeProvider
        .when("/", {
            templateUrl: "route/one"
        })

    .when("/one", {
        templateUrl: "route/one"
    });

    });

templateUrl is the place where you define your view is...In here my view(one.cshtml) is in route folder. Try the following example. Its working example.

<body ng-app="sampleApp">
    <div class="container">
        <div class="row">
            <div class="col-md-3">
                <ul class="nav">
                    <li><a href="#/AddNewOrder"> Add New Order </a></li>
                    <li><a href="#/ShowOrders"> Show Order </a></li>
                </ul>
            </div>
            <div class="col-md-9">
                <div ng-view></div>
            </div>
        </div>
    </div>
   </body>

<script>
sampleApp.config(['$routeProvider',
  function ($routeProvider) {
      $routeProvider
        .when('/AddNewOrder', {
            templateUrl: '/viewStudents.html',
            controller: 'AddOrderController'
        })

        .when('/ShowOrders', {
            templateUrl: '/Home.html',
            controller: 'ShowOrdersController'
        })

        .otherwise({ redirectTo: '/viewStudents' });
  }]);

sampleApp.controller('AddOrderController', function ($scope) {
    $scope.message = 'This is Add new order screen';
});

sampleApp.controller('ShowOrdersController', function ($scope) {
    $scope.message = 'This is Show orders screen';
});

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM