Skip to content

Instantly share code, notes, and snippets.

@amalbuquerque
Forked from anonymous/index.html
Created August 27, 2015 12:44
Show Gist options
  • Save amalbuquerque/7cbd75d9ba3339744a6c to your computer and use it in GitHub Desktop.
Save amalbuquerque/7cbd75d9ba3339744a6c to your computer and use it in GitHub Desktop.
<!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>
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