<!-- origin markup in the view -->
enter a colour: <input class="observe-test" data-ng-model="inputValue" title="{{inputValue}}"/>
<br />
value typed: <span></span>
// directive codes
myApp.directive('observeTest', function () {
return {
restrict: 'C',
link: function (scope, element, attrs) {
attrs.$observe('title', function (newValue) {
attrs.$set('style', 'color:' + newValue);
element.parent().find('span').text(newValue);
})
}
}
});
See the example in Plunker

No comments:
Post a Comment