2016-04-02 7 views
2

Ich bin nicht in der Lage Routing auf andere Seite, was das Problem, das ich weiß nicht, bitte mein Problem lösen.
Ich verwende Eclipse-Java EE IDE für Web-Entwickler.
Version: Mars.1 Mitteilung (4.5.1) Build-ID: 20150924-1200nicht in AngularJS in Eclipse zu routen Lage

// also include ngRoute for all our routing needs 
var myApp = angular.module('myApp', ['ngRoute']); 

// configure our routes 
myApp.config(function($routeProvider) { 

    $routeProvider 

    // route for the home page 
    .when('#/', { 

    templateUrl: 'home.html', 
    controller: 'mainController' 
    }) 

    // route for the about page 
    .when('#/about', { 
    templateUrl: 'about.html', 
    controller: 'aboutController' 
    }) 

    // route for the contact page 
    .when('#/contact', { 
    templateUrl: 'contact.html', 
    controller: 'contactController' 
    }); 
}); 

// create the controller and inject Angular's $scope 
myApp.controller('mainController', function($scope) { 
    // create a message to display in our view 

    $scope.username = 'ranjeet'; 
    $scope.password = 'singh'; 

    $scope.message = 'Everyone come and see how good I look!'; 
}); 



myApp.controller('aboutController', function($scope) { 
    $scope.message = 'Look! I am an about page.'; 
}); 

myApp.controller('contactController', function($scope) { 
    $scope.message = 'Contact us! JK. This is just a demo.'; 
}); 
<!DOCTYPE html> 
<html ng-app="myApp"> 

<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-route.js"></script> 

    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 
</head> 

<body> 
    <header> 
    <nav class="navbar navbar-default"> 
     <div class="container"> 
     <div class="navbar-header"> 
      <a class="navbar-brand" href="/">Angular Routing Example</a> 
     </div> 

     <ul class="nav navbar-nav navbar-right"> 
      <li><a href="#/">home</a> 
      </li> 
      <li><a href="#/about"> About</a> 
      </li> 
      <li><a href="#/contact">Contact</a> 
      </li> 
     </ul> 
     </div> 
    </nav> 
    </header> 

    <div id="main"> 

    <div ng-view></div> 
    </div> 


</body> 

</html> 

Dateistruktur meines Projekts: [file structure of my project1

Antwort

1

Ihre URL-Werte in $routeProvider.when() sollen nicht # enthalten, die intern festgelegt werden, wenn anwendbar (wie standardmäßig html5mode durch Winkel Router deaktiviert ist, so Winkel tut Hash-Standortstrategie verwenden).

Versuchen verändert sich:

$routeProvider 

    // route for the home page 
    .when('#/', { 

    templateUrl: 'home.html', 
    controller: 'mainController' 
    }) 

Um

$routeProvider 

    // route for the home page 
    .when('/', { //do remove # from all registered routes 
     // ^^ no "#" 
    templateUrl: 'home.html', 
    controller: 'mainController' 
    }) 
+0

Sie haben Adleraugen: p ... +1 ..had wenige Satz hinzugefügt von Antwort Bearbeitung –

+0

ich habe alles mit # und nur '/'eventhogh funktioniert nicht –

Verwandte Themen