Angular js使用指令代码中的$windows



好吧,就在我认为我理解AngularJS的时候,我被迷住了。

我有一个应用程序,它使用了许多不同的谷歌地图。我希望用户点击一个标记,然后让系统进入一个新屏幕,显示与点击内容相关的信息。

到目前为止,一切都很顺利。我得到点击事件,然后准备进入相应的屏幕。我当时的代码看起来像:

$window.location.href =  "#/" + ScreenName + "/" + Parameter ;

在这一点上,我得到了错误:

ReferenceError: Can't find variable: $window

哪个搜索告诉我需要注入$window

我尝试了很多不同的方法来注射,但这也是我个人知识库失败的地方

我想我需要让我的app.js文件看起来像这样:

.config([
'$routeProvider', 
function($routeProvider) 
{
$routeProvider.
when("/customer/:cust_gid", {templateUrl: "views/div_Cust.html", controller: "customerController"}).
when("/location/:locn_gid", {templateUrl: "views/div_Locn.html",controller: "locationController"}).
otherwise({redirectTo:  '/utilities'});
}])
.config(function ($windowProvider) {
var $window = $windowProvider.$get();
console.log($window);
});

这对我没有任何帮助。我需要知道我是否很接近,只是语法不正确,或者是否缺少其他东西。

我的index.html文件中是否需要一个包含文件来加载$windows

有人能给我一个幼儿园级别的答案吗。

感激Stan

$windows是一个全局服务,包含在angularjs中。你不需要额外的图书馆参考。

要使用它,注入就像控制器中应该使用它的任何其他服务一样

app.controller('locationController', function($scope, $window)..

最新更新