Skip to content

Instantly share code, notes, and snippets.

@Lokua
Last active September 8, 2016 04:36
Show Gist options
  • Save Lokua/c011278ecfcf5ce0ae7a1991f4c990dd to your computer and use it in GitHub Desktop.
Save Lokua/c011278ecfcf5ce0ae7a1991f4c990dd to your computer and use it in GitHub Desktop.
angular 1 pass promise to directive w/out isolate scope
<div ng-app="app" ng-controller="Controller as vm" directive="directive" promise="vm.promise"></div>
angular
.module('app', [])
.controller('Controller', ['$q', Controller])
.directive('directive', directive)
function Controller($q) {
this.promise = () => $q.when().then(() => console.log('!'))
}
function directive() {
return (scope, _, attrs) => {
const promise = scope.$eval(attrs.promise)
promise().then(() => console.log('?'))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment