0

I don't know why my template is not loading when I access the '/todo-list' state URL.

// main.js - routes

angular.module('myapp', ['ui.router'])
.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('todolist', {
            url: '/todo-list',
            view: {
                '@': {
                    template: 'test!',
                }
            }
        })
        .state('otherwise', {
            url: '*path',
            template: 'Oops! Blank page!' // <- the otherwise is working
        });
}]);  

.

// index.html

<html ng-app="app">
<head>
  <title>Project</title>

  <script src="./js/lib/angular.min.js"></script>
  <script src="./js/lib/angular-ui-router.js"></script>
  <script src="./js/main.js"></script>
</head>

<body>
  <div class="container">
    <ui-view></ui-view>
  </div>
</body>

</html>  

The 'otherwise' works ok, but when I navigate to '/todo-list' it gives to me a blank page. The route is working.. but not the template. Is it something related to the ui-view element?

2
  • can you show us the todoList view please? Commented May 4, 2017 at 2:47
  • @A.Hussien well, the text should load correctly right? Without a .html view for it. The template text in 'otherwise' is working, but I don't know why the '/todo-list' is not working Commented May 4, 2017 at 2:50

1 Answer 1

1

I just change view to views, and it works as expected.

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

app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  $stateProvider
    .state('todolist', {
      views: {
        '@': {
          template: 'test!<button ng-click="clickEvt()">Click me!</button>',
          controller: function($scope) {
            $scope.clickEvt = function() {
              alert('Thanks!');
            };
          }
        }
      }
    })
    .state('otherwise', {
      url: '*path',
      template: 'Oops! Blank page!<button ng-click="go()">todolist</button>', // <- the otherwise is working
      controller: 'defaultCtrl'
    });
}]);
app.controller("defaultCtrl", function($scope, $state) {
  $scope.go = function() {
    $state.go("todolist");
  };
});
<html ng-app="myapp">

<head>
  <title>Project</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.0/angular-ui-router.js"></script>
</head>

<body>
  <div class="container">
    <ui-view></ui-view>
  </div>
</body>

</html>

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

1 Comment

Wow! I lost a lot of time trying to figure it out why! Thank you! I was completly blind!

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.