Reputation: 12487
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');
}
}
I am new to javascript generally and it seems I have made a mistake with this because it doesn't work:
Can anyone show me what it should be please? Thank you.
Upvotes: 1
Views: 5314
Reputation: 77904
I don't sure what you want to see with your example but this is working code:
<html ng-app>
<div ng-controller="TodoCtrl">
<span id="logo">Just a</span><span id="small" >PREVIEW</span>
<button class="btn-large" ng-click="greet()">Press</button>
</div>
Controller
function TodoCtrl($scope, $window) {
$scope.greet = function() {
($window.mockWindow || $window).alert('Hello');
}
}
Hope it will help you
Upvotes: 1
Reputation: 42166
Don't forget to inject $window
service:
app.controller('MainCtrl', function($scope , $window) {
$scope.greet = function() {
($window.mockWindow || $window).alert('Hello');
}
});
Working example: http://plnkr.co/edit/uO9l7n?p=preview
Upvotes: 1