gpt4 book ai didi

javascript - 每次导航到AngularJS中的其他 View /页面时如何检查位置路径

转载 作者:行者123 更新时间:2023-12-03 12:38:39 24 4
gpt4 key购买 nike

我有 Controller 可以检查主页,但它第一次只显示一次。我的问题是如何每次检查

myApp.controller('routeController', ['$scope', '$location', function($scope, $location) {

if($location.path() === '/Home' === true){
alert("1");
}
}]);

然后我的 body 上有 Controller

<body  ng-controller="routeController">

最佳答案

尝试使用 ng-init:

body  ng-controller="routeController" ng-init=initialize()

myApp.controller('routeController', ['$scope', '$location', function($scope, $location) {

$scope.initialize = function()
{
if($location.path() === '/Home' === true){
alert("1");
}
}]);
}

关于javascript - 每次导航到AngularJS中的其他 View /页面时如何检查位置路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23611089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com