Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ui-router not rendering views

I recently split out a rails app I had and created the front end as a separate app with yeoman. For some reason my views no longer render, for example my app defines:

    'use strict';

    var actionTrackApp = angular.module('actionTrackApp', [ 'ui.router', 'ngGrid']);
    actionTrackApp.config(function($locationProvider) {
      return $locationProvider.html5Mode(true);
    });
    actionTrackApp.config(function($stateProvider){
      $stateProvider
        .state("packageIndex", {
          url: "/packages",
          views: {
            "main": {
              controller: "ApplicationCtrl",
              template: "<h1>Test</h1>"
            },
            "": {
              template: "<h1>Test2</h1>"
            }
          },
          resolve: {
            test: function(){
              console.log("test")
            }
          }
        })  
    });

and in my index.html file I have:

bodytag ng-app="actionTrackApp" ng-controller="ApplicationCtrl">
    your site or application content here<a href='/packages'>Package Index</a>

    <div ng-view="main" class="container"></div>
    <div ng-view=""></div>
/bodytag

When i click the link the resolve property does resolve and I see "test" in the console. I tried attaching $routeChangeStart/success watches on applicaiton controller but neither start/success fire here.

like image 988
jvans Avatar asked Oct 02 '22 19:10

jvans


1 Answers

I took a look at your code and found a couple issues

  1. to reference ui-router views, you must use the directive ui-view, not ng-view
  2. the "" view is incorrectly defined - you must use a valid key name, I changed it to aand updated the reference in the html

After I made these changes, all works as expected here: http://plnkr.co/edit/lxAUGMqajwI461VKz8xo

ps: I went ahead and used ui-sref on your link instead of hard-coding the /package url...

like image 82
bendalton Avatar answered Oct 13 '22 10:10

bendalton