Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angularjs中的stateprovider-不呈现ui视图_Angularjs_Angular Ui Router - Fatal编程技术网

angularjs中的stateprovider-不呈现ui视图

angularjs中的stateprovider-不呈现ui视图,angularjs,angular-ui-router,Angularjs,Angular Ui Router,好的。我被这个零件卡住了两天。我知道的一切都试过了。 我已加载ui路由器并定义stateprovider。我的UI如网站中的几个示例所示。但当我运行时,它不会显示我的ui视图 Index.html <body ng-app='ngBRep'> <div> <div data-ng-include="'app/layout/shell.html'"></div> </div> <!--Angular--> <s

好的。我被这个零件卡住了两天。我知道的一切都试过了。 我已加载ui路由器并定义stateprovider。我的UI如网站中的几个示例所示。但当我运行时,它不会显示我的ui视图

Index.html

<body  ng-app='ngBRep'>
<div>
    <div data-ng-include="'app/layout/shell.html'"></div>
</div>
<!--Angular-->
<script src="scripts/angular.js"></script>
<script src="scripts/angular-ui-router.js"></script>
</body>
routes.js

var app = angular.module('ngBRep');

app.config(['$stateProvider', '$urlRouterProvider', routeConfigurator]);

function routeConfigurator($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/");
    $stateProvider
      .state('/', {
          url: '/',
          templateUrl: 'app/views/entry.html'
      })
        .state('profile', {
            url: '/profile',
            templateUrl: 'app/views/profile.html'
        });
    // Send to login if the URL was not found

}
我的期望是当我浏览index.html时,我应该看到 壳 侧面图

但我只有壳

最糟糕的是,在我们的项目中,有一个现有的网站正是这样做的,而且它工作正常

任何帮助都将不胜感激。谢谢。

有一个工作区。本例中的问题与以下事实有关,即我们正在使用两个功能(事实上,这两个功能并非预期/设计为协同工作):

  • ng include
    -填充根视图(通常是
    index.html
    的一部分)
  • ui路由器
    -指向尚未加载的
  • 事实上,include的执行晚于对
    $urlRouterProvider的
    ui路由器的默认调用。否则(“/”
因此,虽然此模板包含在root index.html中

<div data-ng-controller="shell as vm">
    SHELL
    <div ui-view></div>
</div>
通过这种方式,我们解决了加载时间上的差异(路由器比包含的模板更快准备好,所以错过了目标)


检查是否在index.html中有app.js的脚本元素和routes.js的脚本元素?profile.html在哪里?谢谢Radim。成功了。我检查了另一个正在运行的代码,它在app.js app.run中有以下代码(['$route','$rootScope','$q','$state',function($route,$rootScope,$q,$state){});[cont]虽然函数中没有任何内容,但我猜$route、$routeScope的注入起了一些作用。实际上,这带来了新的问题。当我试图通过在浏览器中提供url直接浏览/profile/series时,它总是转到“/”,因为我有$state.go(“/”);在壳中,首先加载壳。请帮忙。如果您想要我的新路线,请告诉我。jsf找到支持我第二条评论的链接。
var app = angular.module('ngBRep', [
        'ui.router' 
]);
var app = angular.module('ngBRep');

app.config(['$stateProvider', '$urlRouterProvider', routeConfigurator]);

function routeConfigurator($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/");
    $stateProvider
      .state('/', {
          url: '/',
          templateUrl: 'app/views/entry.html'
      })
        .state('profile', {
            url: '/profile',
            templateUrl: 'app/views/profile.html'
        });
    // Send to login if the URL was not found

}
<div data-ng-controller="shell as vm">
    SHELL
    <div ui-view></div>
</div>
app.controller('shell', function($scope, $state, ....){
   $state.go("/");
});