在URL更改Angularjs之后广播



我想在$ window.location

之后播放一些数据

因此,在我执行我拥有的searchSelect函数的第一个JS文件中;

$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位置更改后,我该如何进行此广播?谢谢

您需要进行两个更改:

  1. 在更改URL之前使用广播。
  2. 使用Rootscope进行广播。

即。使用此语句:

$rootScope.$broadcast('searched', {type: item.type})

此之前

$window.location.href = url;

最新更新