0

I'am not getting what is the problem, I have an index.html file and an app.js file

  1. Index.html contains two ui-sref inside anchor tag
  2. app.js as stateprovider. Please solve the issue. Thanks for taking out your precious time

var app=angular.module('myApp',['ui.router']);
app.config(function($stateprovider){
    var home=
        {
            name:'home',
            url:'/home',
            template:"<h1>Home</h1>",
            controller: 'myCtrl'
        };
    var contacts=
        {
            name:'contacts',
            url:'/contacts',
            template:"<h1>Contacts</h1>",
            controller: 'myCtrl'
        };
        $stateprovider.state(home)
        $stateprovider.state(contacts)
});
app.controller("myCtrl",function($scope,$http){
})
<!doctype html>
<html ng-app="myApp">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-route.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.20/angular-ui-router.js"></script>
    <script src="https://unpkg.com/[email protected]/release/angular-ui-router.js"></script>
    <script src="./app.js"></script>  
  </head>
  <body  >
      <div ng-controller="myCtrl">
        <ul>
          <li><a ui-sref="home">Home</a></li>
          <li><a ui-sref="contacts">Contacts</a></li>
        </ul>  
        <div>
          <div ui-view>
          </div>    
        </div>
      </div>
  </body>
</html>

3
  • Why do you have 2 CDNs for ui-router in html? Commented Feb 27, 2021 at 8:13
  • Prevoiusly, I had only one CDN, just for checking I put one more but that still doesn't solve the problem Commented Feb 27, 2021 at 8:20
  • try changing $stateprovider to $stateProvider. Also an elaborate error message would help us more to debug the problem Commented Feb 27, 2021 at 12:44

1 Answer 1

1

If you:

  • keep only one script for angular router(version 1.0 is the latest)

  • replace $stateprovider with $stateProvider

it works fine:

var app=angular.module('myApp',['ui.router']);
app.config(function($stateProvider){
    var home=
        {
            name:'home',
            url:'/home',
            template:"<h1>Home</h1>",
            controller: 'myCtrl'
        };
    var contacts=
        {
            name:'contacts',
            url:'/contacts',
            template:"<h1>Contacts</h1>",
            controller: 'myCtrl'
        };
        $stateProvider.state(home)
        $stateProvider.state(contacts)
});
app.controller("myCtrl",function($scope,$http){
})
<!doctype html>
<html ng-app="myApp">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
   
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.20/angular-ui-router.js"></script>
   
    <script src="./app.js"></script>  
  </head>
  <body  >
      <div ng-controller="myCtrl">
        <ul>
          <li><a ui-sref="home">Home</a></li>
          <li><a ui-sref="contacts">Contacts</a></li>
        </ul>  
        <div>
          <div ui-view>
          </div>    
        </div>
      </div>
  </body>
</html>

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

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.