AngularJS-窗口警报加载 [英] AngularJS - Window alert onload

查看:77
本文介绍了AngularJS-窗口警报加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在使用出色的angularJS库。我正在尝试获取一个简单的窗口警报,以进行页面加载。这是我正在使用的代码:

I am just using the fantastic library that is angularJS. I am trying to get a simple window alert to come up on page load. This is the code I am using:

$scope.greet = function() {
    ($window.mockWindow || $window).alert('Hello World');
  }
}

我一般对javascript还是陌生的,似乎我有犯了一个错误,因为它不起作用:

I am new to javascript generally and it seems I have made a mistake with this because it doesn't work:

http://jsfiddle.net/AQ533/5/

有人可以告诉我它应该是什么吗?谢谢。

Can anyone show me what it should be please? Thank you.

推荐答案

别忘了注入 $ window 服务

Don't forget to inject $window service:

app.controller('MainCtrl', function($scope , $window) {
  $scope.greet = function() {
    ($window.mockWindow || $window).alert('Hello');
  }
});

工作示例: http://plnkr.co/edit/uO9l7n?p=preview

这篇关于AngularJS-窗口警报加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆