Skip to content

Instantly share code, notes, and snippets.

@xcarpentier
Last active August 29, 2015 14:07
Show Gist options
  • Save xcarpentier/5b02f5c43e245fc7b3b8 to your computer and use it in GitHub Desktop.
Save xcarpentier/5b02f5c43e245fc7b3b8 to your computer and use it in GitHub Desktop.
<div my-example max="77"></div>
function myExample() {
var directive = {
restrict: 'EA',
template: '<div>hello world</div> \
<div>max={{exVm.max}} \
<input ng-model="exVm.max"/> \
</div> \
<div>min={{exVm.min}} \
<input ng-model="exVm.min"/> \
</div> \
',
scope: {
max: '='
},
link: linkFunc,
controller : DirCtrl,
controllerAs: 'exVm'
};
return directive;
/* @ngInject */
function DirCtrl($scope) {
//Injecter $scope pour la comparaison
/* jshint validthis:true */
var exVm = this;
exVm.min = 3;
exVm.max = $scope.max;
console.log('CTRL: $scope.max = %i', $scope.max);
console.log('CTRL: exVm.min = %i', exVm.min);
console.log('CTRL: exVm.max = %i', exVm.max);
}
/* @ngInject */
function linkFunc(scope, el, attr, ctrl) {
console.log('LINK: scope.max = %i', scope.max);
console.log('LINK: scope.exVm.min = %i', scope.exVm.min);
console.log('LINK: scope.exVm.max = %i', scope.exVm.max);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment