0

I am using angular-ui-router tutorial.

It does not work when i want to load home.html page.

I defined 3 states for each page and define their template url,but no navigation is working at all.

http://localhost:8080/index.html#/home.

this is index.html :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>catalogue</title>
<link rel="stylesheet" type="text/css" 
href="node_modules/bootstrap/dist/css/bootstrap.min.css" />

<link rel="stylesheet" type="text/css" 
href="css/myStyle.css" />


</head>
<body ng-app="MyApp" >

<div ui-view >
</div>

<script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
<script type="text/javascript" src="node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>

this is app.js :

var app=angular.module("MyApp",['ui.router']);


app.config(function($stateProvider,$urlRouterProvider) {
    $stateProvider.state('home',{
        url:'/home',
        templateUrl: 'views/home.html',
        controller: 'HomeController'
    });
    $stateProvider.state('chercher',{
        url:'/chercher',
        templateUrl: 'views/chercher.html',
        controller: 'MyController'
    });
    $stateProvider.state('newProduct',{
        url:'/newProduct',
        templateUrl: 'views/newProduct.html',
        controller: 'NewProductController'
    });

});  

app.controller('HomeController', function() {

});

app.controller('NewProduitController', function() {

});

home.html:

<div>
<h1>home</h1>

</div>
2
  • What errors does it throw? Commented Jun 15, 2017 at 11:04
  • nothing. but the browser does not show anything Commented Jun 15, 2017 at 11:05

2 Answers 2

1

Set default URL state.

var app=angular.module("MyApp",['ui.router']);


app.config(function($stateProvider,$urlRouterProvider) {
    $stateProvider.state('home',{
        url:'/home',
        templateUrl: 'views/home.html',
        controller: 'HomeController'
    });
    $stateProvider.state('chercher',{
        url:'/chercher',
        templateUrl: 'views/chercher.html',
        controller: 'MyController'
    });
    $stateProvider.state('newProduct',{
        url:'/newProduct',
        templateUrl: 'views/newProduct.html',
        controller: 'NewProductController'
    });
   // add this code 
   $urlRouterProvider.otherwise('/home');

});  

app.controller('HomeController', function() {

});

app.controller('NewProduitController', function() {

});

open this link in browser http://localhost:8080/

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

Comments

0

i solved the problem.

I used ui-sref instead of writing directly in the URL browser.

<button ui-sref="home" >Home</button>

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.