[英]angular.js:12520 TypeError: Cannot read property 'post' of undefined
[英]$window.location.href (angular.js:12520 TypeError: Cannot set property 'href' of undefined)
我嘗試使用ng-click單擊時使用指令的功能進行重定向。
html:
<a ng-click="navbarlinksCtrl.clickedfr()" ng-class="{active: clickedfr()}">FR</a><br>
<a ng-click="navbarlinksCtrl.clickeden()">EN</a>
指令:
(function($) {
'use strict';
angular
.module('eeeee')
.directive('navBarLinks', navBarLinks);
navBarLinks.$inject = ['CONTEXT'];
/**
* Directive which shows the navigation bar links
* @memberof eeeee
* @ngdoc directive
* @name navBarLinks
* @restrict E
* @example
* <nav-bar-links><div>Content of navigation bar links</div></nav-bar-links>
*/
function navBarLinks(CONTEXT) {
var directive = {
bindToController: {
activeLanguagesAsLocales: '@',
current: '@',
lang: '@',
userPreferredLanguage: '@',
siteActiveLanguages: '@'
},
controller: NavBarLinksController,
controllerAs: 'navbarlinksCtrl',
restrict: 'E',
scope: {},
templateUrl: CONTEXT.contextPath + '/modules/reeeeeetemplate/javascript/components/navBarLinks/navBarLinks.tpl.html'
};
return directive;
}
NavBarLinksController.$inject = ['CONTEXT', '$timeout', 'loginService', 'openPageService', 'globalContextService', 'responsiveService'];
/**
* Controller which shows the login header
* @memberof eeeeeeeeeeee
* @name navBarLinksController
* @ngdoc controller
*/
function NavBarLinksController($location, $window, CONTEXT, $timeout, loginService, openPageService, globalContextService, responsiveService ) {
var vm = this;
vm.clickedfr=clickedFr;
vm.clickeden=clickedEn;
// vm.isOpen = false;
// vm.username = '';
// vm.password = '';
// vm.forgotPassword = forgotPassword;
// vm.isOpen = false;
// vm.submit = submit;
// vm.resetError = resetError;
// vm.isResponsive = false;
// vm.updateResponsive = updateResponsive;
activate();
/////////////
function activate() {
// updateResponsive();
// addStringEndsWithFunctionIfNotExist();
// openLoginOnTheHomePage();
}
function clickedFr(){
// http://127.0.0.1:8081/fr/home.html
// openPageService.sendMessageOpenPage(CONTEXT.contextPath + "eeeee/home.html");
$window.location.href = "/eeeeee/home";
}
function clickedEn(){
$location.path("/en/home.html");
}
//
// /**
// * Redirect to the password reset page
// * @memberof LoginController
// * @function forgotPassword
// */
// function forgotPassword() {
// openPageService.sendMessageOpenPage(CONTEXT.contextPath + vm.forgotPasswordPath, "openLogin=false");
// }
//
}
})();
我收到錯誤angular.js:12520 TypeError:無法設置未定義的屬性“ href”
嘗試$ window.location.href和$ location.path
它沒有用,我也不耐心。 因此,我決定使其變得更容易:
我用window.location。 有效 !
如果您使用angularjs,請使用此$ location.path(“ / home.html”);
如果使用$stateProvider
來構建路由,則可以這樣進行:
$state.go("/fr/home");
不要忘記注入$state
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.