0

I am brand new to AngularJs and after following some tutorials I decided to try to implement a one page app into one of my projects. I have it working but I had one question about this code. Could I change what is shown on the first page before they navigate to anything? I don't want it shown on every page just when they first land on it before clicking any links.

var app=angular.module('single-page-app',['ngRoute']);
app.config(function($routeProvider){
      $routeProvider
          .when('/',{
                templateUrl: 'home.html'
          })
          .when('/about',{
                templateUrl: 'about.html'
          });
});
app.controller('cfgController',function($scope){

    /*      
    Here you can handle controller for specific route as well.
    */
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="single-page-app">
	<div ng-controller="cfgController">
  		<div>
  			<nav>
         			<ul>
        				<li><a href="#/">Home</a></li>
        				<li><a href="#/about">About us</a></li>
      				</ul>
			</nav>
		</div>
  		<br/>
  		<div ng-view>
  		<!--
     			This DIV loads templates depending upon route.
 		-->
  		</div>
  	</div>
</body>

The pages load fine and if I try to add something to the index.html under ng-view it doesn't show up on the page.

1 Answer 1

1

You want to put the content to show up when a user first hits your site under in your "home.html" page which is linked to your "/" route for "ng-view". When a user clicks a link, they will be taken to a new route, and the code/ will be replaced by the route they selected.

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

3 Comments

I would like to make something show on this intial landing page, before they click any links.
Do you have anything in your 'home.html' file?
Oh boy I feel a little bit dumb, I forgot to put content in the home.html file. Thank you for that.

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.