问题
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.
回答1:
I took a look at your code and found a couple issues
- to reference ui-router views, you must use the directive
ui-view
, notng-view
- the "" view is incorrectly defined - you must use a valid key name, I changed it to
a
and 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...
来源:https://stackoverflow.com/questions/19129097/ui-router-not-rendering-views