ui-router不呈现视图

jva*_*ans 5 angularjs yeoman angular-ui-router

我最近拆分了一个我拥有的rails应用程序,并创建了前端作为一个单独的应用程序与自耕农.由于某些原因,我的视图不再呈现,例如我的应用程序定义:

    '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")
            }
          }
        })  
    });
Run Code Online (Sandbox Code Playgroud)

在我的index.html文件中,我有:

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
Run Code Online (Sandbox Code Playgroud)

当我点击链接时,resolve属性确实解析了,我在控制台中看到"test".我尝试在应用程序控制器上附加$ routeChangeStart/success watch,但这里没有启动/成功.

ben*_*ton 4

我查看了您的代码,发现了几个问题

  1. 要引用 ui-router 视图,您必须使用指令ui-view,而不是ng-view
  2. “”视图定义不正确 - 您必须使用有效的键名称,我将其更改为a并更新了 html 中的引用

进行这些更改后,一切都按预期进行: http://plnkr.co/edit/lxAUGMqajwI461VKz8xo

ps:我继续ui-sref在您的链接上使用,而不是对 /package url 进行硬编码...