Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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/1/typescript/8.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 “否则”似乎不起作用_Angularjs_Typescript_Angular Ui Router - Fatal编程技术网

Angularjs “否则”似乎不起作用

Angularjs “否则”似乎不起作用,angularjs,typescript,angular-ui-router,Angularjs,Typescript,Angular Ui Router,我正在尝试让ui.router使用以下设置 export class Router { /* tslint:disable no-unused-variable */ private static $inject: string[] = ["$stateProvider", "$urlRouterProvider", "$locationProvider"]; /* tslint:enable no-unused-variable */ constructor(

我正在尝试让ui.router使用以下设置

export class Router {
    /* tslint:disable no-unused-variable */
    private static $inject: string[] = ["$stateProvider", "$urlRouterProvider", "$locationProvider"];
    /* tslint:enable no-unused-variable */

    constructor($state: ng.ui.IStateProvider, $urlRouter: ng.ui.IUrlRouterProvider, $location: ng.ILocationProvider) {
        $urlRouter.otherwise("/");

        $state.state("default", {
            url: "/",
            views: {
                "header": {
                    templateUrl: "/views/layout/header.html"
                },
                "sidebar": {
                    templateUrl: "/views/layout/side-menu.html"
                },
                "": {
                    templateUrl: "/views/workspace/index.html"
                },
                "footer": {
                },
            }
        });

        $location.html5Mode(true);
    }
}
这是我正在使用的部分文件

<div id="workspace">
    <div id="workspace-header">
        <div data-ui-view="header"></div>
    </div>
    <div id="workspace-container">
        <div>
            <div data-ui-view="sidebar"></div>
        </div>
        <div>
            <div>
                <div>
                    <div id="workspace-view">
                        <div data-ui-view></div>
                    </div>
                    <div id="workspace-footer">
                        <div data-ui-view="footer"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
我不确定这是否相关,也不确定这是否是个问题,但上面的html是使用ng include注入的,就像这样

<div id="dashboard" data-ng-include="'/views/master.html'" data-prevent-touch-scroll></div>
为了清楚起见,我确认路由器被呼叫了


我以为“否则”会导航到url,它会进入默认状态,这将注入部分视图,但它似乎不起作用,我确信我遗漏了一些东西,但我无法找到它。

我用ui视图替换ng include解决了这个问题

<div id="dashboard" data-ui-view data-prevent-touch-scroll></div>

我不确定这是一个解决方案还是一个黑客,但它是有效的

在这种情况下,普朗克总是会帮忙的。没有html5它能工作吗?我会举个例子并更新它。我试着在Plunker中工作,但它似乎为我的style.css和app.js抛出了404。你使用的是哪个版本的Angularjs?你试过这个吗:我使用的是1.3.0-rc.5版。我的页面中确实有基本标签,这似乎是ng include的一个问题。
export class Router {
    /* tslint:disable no-unused-variable */
    private static $inject: string[] = ["$stateProvider", "$urlRouterProvider", "$locationProvider"];
    /* tslint:enable no-unused-variable */

    constructor($state: ng.ui.IStateProvider, $urlRouter: ng.ui.IUrlRouterProvider, $location: ng.ILocationProvider) {
        $urlRouter.otherwise("/");

        $state.state("default", {
            url: "/",
            templateUrl: "/views/master.html",
            onEnter: ["$state", "$timeout", ($state: ng.ui.IStateService, $timeout: ng.ITimeoutService) => {
                $timeout(() => {
                    $state.go("default.master");
                });
            }]
        });

        $state.state("default.master", {
            views: {
                "header": {
                    templateUrl: "/views/layout/header.html"
                },
                "sidebar": {
                    templateUrl: "/views/layout/side-menu.html"
                },
                "": {
                    templateUrl: "/views/workspace/index.html"
                },
                "footer": {
                },
            }
        });

        $location.html5Mode(true);
    }
}