Skip to content

Instantly share code, notes, and snippets.

@magarcia
Last active October 23, 2016 18:47
Show Gist options
  • Save magarcia/384af019aef2ef465f3e08c5b8f905ec to your computer and use it in GitHub Desktop.
Save magarcia/384af019aef2ef465f3e08c5b8f905ec to your computer and use it in GitHub Desktop.
import { Component, Input } from '@angular/core';
@Component({
selector: 'example-component',
})
export class ExampleComponent {
public internalVal = null;
constructor() {}
@Input('externalVal')
set updateInternalVal(externalVal) {
this.internalVal = externalVal;
}
}
var module = angular.module("myApp");
module.directive('exampleDirective', function () {
return {
template: '<div>{{internalVar}}</div>',
scope: {
externalVar: "="
},
controller: function(scope, element) {
scope.$watch('externalVar', function(newVal, oldVal) {
if (newVal !== oldVal) {
scope.internalVar = newVal;
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment