0

This question might sound very generic to some of you but as a newbie i am having trouble in this. Its evident to use ng-view within the home page in order to display other html files within the page but how should i redirect to a new page present in the web app. I mean how to route to completely different web page in a multipage web application.

2 Answers 2

2

Import AngularJs-Route File

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

Then you must add the ngRoute as a dependency in the application module:

var app = angular.module("myApp", ["ngRoute"]);

Use the $routeProvider to configure different routes in your application:

app.config(function($routeProvider) {
$routeProvider
  .when("/", {
    templateUrl : "main.htm"
  })
  .when("/red", {
    templateUrl : "red.htm"
  })
  .when("/green", {
    templateUrl : "green.htm"
  })
  .when("/blue", {
    templateUrl : "blue.htm"
  });
});

STructure Your HTML

<body ng-app="myApp">

<p><a href="#/">Home</a></p>
<a href="#red">Red</a>
<a href="#green">Green</a>
<a href="#blue">Blue</a>

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

For nested views you can use https://github.com/angular-ui/ui-router

Follow https://github.com/angular-ui/ui-router/wiki/Nested-States-&-Nested-Views for reference

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

4 Comments

i want the page to redirect to another page and not to include html in the ng-view, when i click on hyperlinks red green or blue
@jayendrabhatt you mean to a different domain?
no, i mean in "green.htm", can i write ng-view in green.htm and not in the html template file which contain the hyperlinks.
No you cannot, Just use https://github.com/angular-ui/ui-router for that. It allows using nested views.
0

Try searching angular ui-roter how its works and its mechanism . Since angular is a single page application your app needs to be on one base template then expand from their. From base template route in different page but if you want to route to different application use normal hyper link or ui-serf . Go though u-router basic. Also look into ui-serf .

Comments

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.