我正在使用Angular 1.6.3组件创建角度应用程序并使用UI-Router进行导航。但是在使用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>
答案 0 :(得分:0)
看起来已经解决了。在将Ui-Router更新到1.0.0-beta后,它开始工作。