AngularJS Live Example

by nirus

HTML

<script src="http://code.angularjs.org/angular-1.0.0rc5.min.js"></script>
<!doctype html>
<html ng-app="HelloApp">
<body ng-controller="MyCtrl">
<hello-world></hello-world>
</body>
</html>

JavaScript

var app = angular.module('components', [])

	app.controller("MyCtrl", ["$scope","$http", function($scope, $http){    	
        $scope.ctrl = "Works!"
        $scope.http = $http;
    }]);
    app.directive('helloWorld', function () {
        return {
            restrict: 'EC',            
            link:function(scope, elemnt, attrs){
            	console.log("Directive");                                                        
                scope.http.post("/echo/json/", "json=%7B%22name%22%3A%22nirus%22%7D")
                .success(function(data, status) {
                    scope.name = data.name;
                   console.log(data.name)
                }).error(function (status) {
                	console.log("Error occured")
                });
            },            
            template: '<span>Hello {{name}} : it {{ctrl}}</span>'
        }
    })

angular.module('HelloApp', ['components'])