链接1 链接2
我正在尝试获取警报中的当前URL,但是我猜想角度脚本在警报之前首先运行,因此,当我单击链接2时,其显示链接1,反之亦然。在angularjs 1.7中加载页面后,我是否缺少任何内容或要获取页面的URL?
(function () {
var app = angular.module('myApp');
app.controller('initiativesController', ['$scope',
function ($scope) {
$scope.TestInitiatives = "Test";
var url = window.location.pathname.split('/')[1];;
alert(url)
console.log($scope.TestInitiatives);
}
]);
})();
Angular app.js
(function () {
var myapp = angular.module('myApp', ["ui.router"]);
myapp.config(function ($stateProvider, $locationProvider, $urlRouterProvider) {
// For any unmatched url, send to /route1
$urlRouterProvider.otherwise("/route1")
$stateProvider
.state('route1', {
url: "/route1",
templateUrl: "SOC/Views/route1.html",
controller: "route1ctrl"
})
.state('route2', {
url: "/route2",
templateUrl: "SOC/Views/route2.html",
controller: "route2ctrl"
})
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
});
})();