Created
July 13, 2014 12:48
-
-
Save ronihcohen/1241dcc6ab14351b6f41 to your computer and use it in GitHub Desktop.
angular-controller-as.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body ng-app="playground"> | |
<div ng-controller="mainController as main"> | |
<h1>Hello {{main.data.name}} ! </h1> | |
<button ng-click="main.greet()">greet</button> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script> | |
<script type="text/javascript"> | |
function mainController(http,log){ | |
this.data ={ | |
name: 'Roni' | |
} | |
this.greet = function(){ | |
http.get('http://demo2005784.mockable.io/test').success(function(res){ | |
log.info('name: '+res.name); | |
this.data.name=res.name; | |
}.bind(this)); | |
}; | |
}; | |
angular.module('playground',[]).controller({ | |
'mainController': ['$http','$log',mainController] | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment