0

我正在使用 Angular 1.6.3 组件和使用 UI-Router 的导航创建一个 Angular 应用程序。但我无法在使用 UI-Router 时显示屏幕。我在控制台中没有收到任何错误,因此无法识别正在发生的事情。有人能帮我吗。

该代码位于以下位置 https://github.com/vipinnair/angular-1.6.3-component-ui-router

(function () {
    'use strict'

    var main = angular.module("main", ["security", "registration", "shared", "ui.router"]).config(function ($stateProvider) {
        $stateProvider.state('login', {
            url: '/login',
            template: '<h1>test</h1>'
        })
    })

    function mainController($location, restService, $rootScope) {
        var self = this;
        self.$onInit = function () {
            var dns = $location.host();
            if ($location.host().indexOf('tenant')) {
                $rootScope.tenant = "tenant";
            }
            else {
                $rootScope.tenant = "tenant2";
            }

            // TODO: Remove this hardcoding.
            $rootScope.tenant = "tenant";
            $rootScope.language = "en-CA";
            var url = "/" + $rootScope.tenant + "/base/set/" + $rootScope.language
            restService.get(url, "").then(function (response) {
                if (response.success === false) {
                    console.debug("Unable to set the tenant and language -", message.message)
                }
            });
        }
    }

    main.component("mainComponent", {
        templateUrl: "main/main.component.html",
        controllerAs: "model",
        controller: ["$location", "restService", "$rootScope", mainController]
    });

    return main;
})();


(function () {
    'use strict'

    var registration = angular.module("registration", []);

    function registrationController() {
        var model = this;
        model.login = function () {
        };
    }

    registration.component("registrationComponent", {
        templateUrl: "registration/registration.component.html",
        controllerAs: "model",
        controller: registrationController
    });

    return registration;
})();

(function () {
    'use strict'

    var security = angular.module("security", []);

    // ----------------------  Private methods ................................. //
    // fetch security cms content.
    function fetchPageContent(contentService) {
        // TODO: tenant/En-CA should be dynamic. Move urls to config.
        var url = "tenant" + "/page/security/" + "en-CA";
        contentService.fetchPageContent(url).then(function () {
            model.securityPageContent = response;

        });
    }

    // Login call back.
    function loginCallback(response) {
        if (response.success) {
            authServices.SetCredentials($scope.emailAddress, $scope.password);
            $location.path("/Home");
        }
    }


    // ---------------------------- Public Methods ................................ //

    function securityController($rootScope, contentService, authServices) {
        var model = this;

        model.$onInit = function () {

            // Set CMS pages.
            fetchPageContent(contentService)
        }

        model.login = function () {
            authServices.ClearCredentials();
            debugger;
            // spinner.
            authServices.login($rootScope.tenant, userData.emailAddress, userData.password, loginCallback);
        };
    }

    security.component("securityComponent", {
        templateUrl: "security/security.component.html",
        controllerAs: "model",
        controller: ["$rootScope", "contentService", "authServices", securityController]
    });

    return security
})();

(function () {
    'use strict'

    var app = angular.module('fxApp', ['main']);

    app.config(['$qProvider', function ($qProvider) {
        $qProvider.errorOnUnhandledRejections(false);
    }]);

    return app;
})();

 <main-component></main-component>

    <!-- MAIN CONTENT AND INJECTED VIEWS -->

<div id="main" ui-view>
</div>
4

1 回答 1

0

看起来这已经解决了。将 Ui-Router 更新到 1.0.0-beta 后,它开始工作。

于 2017-04-08T15:14:15.230 回答