将AngularJS 1.2 $位置服务注入到无法在PhoneGap 3.0中运行的控制器中

时间:2013-10-13 21:05:37

标签: windows-phone-7 angularjs cordova windows-phone-7-emulator

在具有PhoneGap 3.0和AngularJS 1.2的Windows Phone 7.1模拟器中,为什么这不起作用:

angulargap.controller('HomeController', ['$scope', '$routeParams', '$location',
function ($scope, $routeParams, $location) {
    $scope.$routeParams = $routeParams;
    $scope.$location = $location;
    $scope.message = "AngularJS!";
}]);

错误讯息:

ERROR:Error: [$injector:cdep] Circular dependency found: 
http://errors.angularjs.org/1.2.0-rc.2/$injector/cdep?p0=

虽然这有效:

angulargap.controller('HomeController', ['$scope', '$routeParams',
function ($scope, $routeParams) {
    $scope.$routeParams = $routeParams;
    $scope.message = "AngularJS!";
}]);

在此特定方案中注入$ location服务出了什么问题?所有这些功能都适用于桌面浏览器中的Chrome和Internet Explorer。但它不适用于Windows Phone 7设备模拟器,也不适用于物理设备本身。

1 个答案:

答案 0 :(得分:3)

得到它们...... AngularJS / PhoneGap / WindowsPhone组合存在大量问题。这个是https://github.com/angular/angular.js/issues/2303?source=cc#issuecomment-20770025解决的。

基本上,因为Windows Phone使用带有单个正斜杠(x-wmapp0:/)的奇怪协议前缀,所以$ location初始化程序会发生错误并触发错误,该错误会在这个奇怪的错误消息中以自己的方式暴露自身,与错误完全无关:-(

我准备就GitHub上的AngularJS回购提出一个拉动请求。