0

I tried the UI Router sample application (plnkr.co/edit/u18KQc?p=preview) but when i'm running the same code in my browser, it's not working. Any recent changes to API ? Till " $urlRouterProvider.otherwise("/route1")" It's working as it's routed to "/route1" initially.

working like this

Additional Files with index.html (in same directory):

  • route1.html
  • route1.list.html
  • route2.html
  • route2.list.html

    var myapp = angular.module('myapp', ["ui.router"])
    myapp.config(function($stateProvider, $urlRouterProvider){
      // For any unmatched url, send to /route1
      $urlRouterProvider.otherwise("/route1")
    
      $stateProvider
        .state('route1', {
            url: "/route1",
            templateUrl: "route1.html"
        })
          .state('route1.list', {
              url: "/list",
              templateUrl: "route1.list.html",
              controller: function($scope){
                $scope.items = ["A", "List", "Of", "Items"];
              }
          })
    
        .state('route2', {
            url: "/route2",
            templateUrl: "route2.html"
        })
          .state('route2.list', {
              url: "/list",
              templateUrl: "route2.list.html",
              controller: function($scope){
                $scope.things = ["A", "Set", "Of", "Things"];
              }
          })
    })
    

1 Answer 1

1

AngularJS loads templates via ajax calls and such calls can be only made by browser when it runs a page from server, loading your application from a filesystem (file:/// in address bar) won't work.

You can use a simple server e.g. python -m http.server

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

6 Comments

means what changes need to be made ?
Just open: embed.plnkr.co/u18KQc/preview - it should work that way. It doesn't handle being inside iframe well.
It's working on plnkr, i'm talking about when i downloaded the code & run it on my PC as it is, it's not working ?
Ah, sorry, I didn't get that. Did you try running it from a local server? (instead from filesystem) I'll edit the answer out to reflect that suggestion.
I just double clicked on index.html to run the downloaded file, it wssnt able to load the CDN files as it;s without http so i downloaded but still it;s not working ! Neither other angular projects downloaded !
|

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.