2016-05-30 8 views
0

Hallo, ich habe ein Problem mit meinem Code. Wenn ich auf die Link-Seite klicke, wird sie nicht neu geladen.Verwenden von TemplateUrl funktioniert nicht

ist hier ein HTML und JS-Code:

var app=angular.module('mainApp',['ngRoute']); 
 
app.config(function($routeProvider){ 
 
     $routeProvider 
 
      .when('/',{ 
 
       templateUrl: 'home.html' 
 
      }) 
 
      .when('/about',{ 
 
       templateUrl: 'about.html' 
 
      }); 
 
\t \t .when('/contact',{ 
 
       templateUrl: 'contact.html' 
 
      }); 
 
\t \t .otherwise({ redirectTo: '/'}); 
 
}); 
 
app.controller('mainCtrl',function($scope){ 
 
\t 
 
});
<div ng-controller="mainCtrl"> 
 
\t \t <div> 
 
\t \t \t <nav> 
 
\t \t \t \t <ul> 
 
\t \t \t \t \t <li><a href="#/">Home</a></li> 
 
\t \t \t \t \t <li><a href="#/about">About us</a></li> 
 
\t \t \t \t \t <li><a href="#/contact">Contact</a></li> 
 
\t \t \t \t </ul> 
 
\t \t \t </nav> 
 
\t \t </div> 
 
\t <br/> 
 
\t \t <div ng-view > 
 
\t \t 
 
\t \t </div> 
 
</div>

Haben Sie eine Ahnung, was `s falsch?

+1

Sie versuchen, auf '.when' off ein Trennzeichen'; ' –

+0

entfernen Semikolon nach, wenn() –

+0

wenn ich löschen; vorher .wenn nichts geändert wird – Ernest

Antwort

0

dieses Semikolon

var app=angular.module('mainApp',['ngRoute']); 
    app.config(function($routeProvider){ 
      $routeProvider 
       .when('/',{ 
        templateUrl: 'home.html' 
       }) 
       .when('/about',{ 
        templateUrl: 'about.html' 
       }) 
       .when('/contact',{ 
        templateUrl: 'contact.html' 
       }) 
       .otherwise({ redirectTo: '/'}); 
    }); 
    app.controller('mainCtrl',function($scope){ 

    }); 
+0

Seiten in der Adresse ändern sich, aber in meiner ng-Ansicht passiert nichts. Kannst du damit helfen? – Ernest

0

Remove Versuchen (;) für die zweite und thirs .when Fälle

var app=angular.module('mainApp',['ngRoute']); 
app.config(function($routeProvider){ 
    $routeProvider 
     .when('/',{ 
      templateUrl: 'home.html' 
     }) 
     .when('/about',{ 
      templateUrl: 'about.html' 
     }) 
     .when('/contact',{ 
      templateUrl: 'contact.html' 
     }) 
     .otherwise({ redirectTo: '/'}); 
}); 
0

Öffnen Sie die Konsole. Wahrscheinlich fehlt Ihr BASE-Tag. Fügen Sie es dem HEAD-Tag hinzu.

<base href="/" /> 
Verwandte Themen