我想在 $window.location 之后广播一些数据
因此,在我的第一个 js 文件中,我执行了 searchSelect 函数;
$scope.searchSelect = function (item) {
var url = "http://" + $window.location.host + "/import.aspx?key=IMPORT_" + item.type;
$window.location.href = url;
$scope.$broadcast('searched', {type: item.type})
}
在第二个js文件中我有:
$scope.$on('searched', function (event, args) {
console.log(args.type);
})
但是console.log不会出现。
URL位置更改后如何进行此广播?谢谢
最佳答案
您需要进行两项更改:
- 在更改网址之前使用广播。
- 使用 rootscope 进行广播。
即 使用这个语句:
$rootScope.$broadcast('searched', {type: item.type})
在此之前
$window.location.href = url;
关于javascript - AngularJS 中 url 更改后的广播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43756594/