Skip to content

Instantly share code, notes, and snippets.

@mchung
Created May 1, 2012 18:52
Show Gist options
  • Save mchung/2570456 to your computer and use it in GitHub Desktop.
Save mchung/2570456 to your computer and use it in GitHub Desktop.
hello-window
<!doctype html>
<html ng-app="MyApp">
<script src="http://code.angularjs.org/angular-1.0.0rc7.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', []);
app.factory('greeter', function($window) {
return {
greet: function(text) {
$window.alert(text);
}
}
});
app.controller('MainCtrl', ['$scope', 'greeter', function($scope, greeter) {
$scope.alert = function(msg) {
greeter.greet("Factory Powered Greeter: " + msg);
}
}]);
</script>
<body ng-controller="MainCtrl">
<input type="text" ng-init="greeting='Hello World!'" ng-model="greeting" />
<button ng-click="alert(greeting)">ALERT</button>
</body>
</html>
<!doctype html>
<html ng-app="MyApp">
<script src="http://code.angularjs.org/angular-1.0.0rc7.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', []).
controller('MainCtrl', ['$scope', '$window', function($scope, $window) {
$scope.$window = $window;
}]);
</script>
<body ng-controller="MainCtrl">
<input type="text" ng-init="greeting='Hello World!'" ng-model="greeting" />
<button ng-click="$window.alert(greeting)">ALERT</button>
</body>
</html>
@mchung
Copy link
Author

mchung commented May 1, 2012

@slowpoison
Copy link

Thanks for creating this. I used the latter and it worked!
Funny how the angular.js example is still broken. Been a year.

@kamalreddy
Copy link

Are the angular guys even aware of this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment