-
-
Save amalbuquerque/7cbd75d9ba3339744a6c to your computer and use it in GitHub Desktop.
// source http://jsbin.com/bicigoboso
This file contains 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 ng-app="hello"> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> | |
<script type="text/ng-template" id="nonHttpTemplateUrl"> | |
<p class="hello__content">hello, world</p> | |
</script> | |
</head> | |
<body> | |
<div hello></div> | |
<div ng-controller='myController as cont'> | |
{{ cont.abcdef }} | |
</div> | |
<script id="jsbin-javascript"> | |
var meter = angular.module('hello', []) | |
.directive( 'hello', function() { | |
return { | |
restrict: 'A', | |
replace: true, | |
template: '<p class="hello__content">hello</p>', | |
//templateUrl: 'nonHttpTemplateUrl', | |
}; | |
}) | |
.controller('myController', function($q) { | |
var cont = this; | |
cont.abcdef = 'zaratrustrau'; | |
var okToGreet = function(n){ | |
return false; | |
}; | |
function asyncGreet(name) { | |
// perform some asynchronous operation, | |
// resolve or reject the promise when appropriate. | |
return $q(function(resolve, reject) { | |
setTimeout(function() { | |
console.log('Working inside the promise!'); | |
if (okToGreet(name)) { | |
resolve('Hello, ' + name + '!'); | |
} else { | |
reject('Greeting ' + name + ' is not allowed.'); | |
} | |
}, 2000); | |
}); | |
} | |
var promise = asyncGreet('Robin Hood'); | |
promise.then(function(greeting) { | |
console.log('Success afther the promise: ' + greeting); | |
}, function(reason) { | |
console.log('Failed afther the promise: ' + reason); | |
}); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var meter = angular.module('hello', []) | |
.directive( 'hello', function() { | |
return { | |
restrict: 'A', | |
replace: true, | |
template: '<p class="hello__content">hello</p>', | |
//templateUrl: 'nonHttpTemplateUrl', | |
}; | |
}) | |
.controller('myController', function($q) { | |
var cont = this; | |
cont.abcdef = 'zaratrustrau'; | |
var okToGreet = function(n){ | |
return false; | |
}; | |
function asyncGreet(name) { | |
// perform some asynchronous operation, | |
// resolve or reject the promise when appropriate. | |
return $q(function(resolve, reject) { | |
setTimeout(function() { | |
console.log('Working inside the promise!'); | |
if (okToGreet(name)) { | |
resolve('Hello, ' + name + '!'); | |
} else { | |
reject('Greeting ' + name + ' is not allowed.'); | |
} | |
}, 2000); | |
}); | |
} | |
var promise = asyncGreet('Robin Hood'); | |
promise.then(function(greeting) { | |
console.log('Success afther the promise: ' + greeting); | |
}, function(reason) { | |
console.log('Failed afther the promise: ' + reason); | |
}); | |
});</script></body> | |
</html> |
This file contains 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
var meter = angular.module('hello', []) | |
.directive( 'hello', function() { | |
return { | |
restrict: 'A', | |
replace: true, | |
template: '<p class="hello__content">hello</p>', | |
//templateUrl: 'nonHttpTemplateUrl', | |
}; | |
}) | |
.controller('myController', function($q) { | |
var cont = this; | |
cont.abcdef = 'zaratrustrau'; | |
var okToGreet = function(n){ | |
return false; | |
}; | |
function asyncGreet(name) { | |
// perform some asynchronous operation, | |
// resolve or reject the promise when appropriate. | |
return $q(function(resolve, reject) { | |
setTimeout(function() { | |
console.log('Working inside the promise!'); | |
if (okToGreet(name)) { | |
resolve('Hello, ' + name + '!'); | |
} else { | |
reject('Greeting ' + name + ' is not allowed.'); | |
} | |
}, 2000); | |
}); | |
} | |
var promise = asyncGreet('Robin Hood'); | |
promise.then(function(greeting) { | |
console.log('Success afther the promise: ' + greeting); | |
}, function(reason) { | |
console.log('Failed afther the promise: ' + reason); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment