简体   繁体   中英

Angular JS ng-view

I am currently trying to build a angular js menu here is my code I can't seem to get the pages to load at all. Am I missing something? have I included all the correct scripts required. Very new to angular.

 // create the module and name it scotchApp var scotchApp = angular.module('RoutingApp', ['ngRoute']); // configure our routes scotchApp.config(function($routeProvider) { $routeProvider // route for the home page .when('/', { templateUrl: 'http://www.habboholiday.net/pages/home.html', controller: 'mainController' }) // route for the about page .when('/about', { templateUrl: 'pages/about.html', controller: 'aboutController' }) // route for the contact page .when('/contact', { templateUrl: 'pages/contact.html', controller: 'contactController' }); }); // create the controller and inject Angular's $scope scotchApp.controller('mainController', function($scope) { // create a message to display in our view $scope.HomeMessage = 'Home Controller Called !!!'; }); scotchApp.controller('aboutController', function($scope) { $scope.AboutMessage = 'About Controller Called !!!'; }); scotchApp.controller('contactController', function($scope) { $scope.ContactMessage = 'Contact Controller Called !!!'; }); 
 <!DOCTYPE html> <!-- define angular app --> <html ng-app="RoutingApp"> <head> <!-- SPELLS --> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script> <script src="script.js"></script> </head> <body ng-controller="mainController"> <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="#"><i class="fa fa-home"></i>Home</a></li> <li><a href="#about"><i class="fa fa-shield"></i>About</a></li> <li><a href="#contact"><i class="fa fa-comment"></i>Contact</a></li> </ul> </div> </nav> <div id="main"> <!-- angular templating : This is where content will be injected --> <div ng-view></div> </div> </body> </html> 

I guess you have missed ng-app directive. Add that to your HTML and try.

You need to add ng-app to your html element

<html ng-app="RoutingApp">
  ....
</html>

In addition, you can move your Angular script references to the bottom of your body or they should at least be contained within <head> tags

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