Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
{{aModelVar}}<br/>
<input ng-model="aModelVar"><br/>
should be updated: <iso2symbol cur-iso="aModelVar"></iso2symbol>
should remain static: <iso2symbol cur-iso="nonModelText"></iso2symbol>
</div>
JavaScript
var myApp = angular.module('myApp', []);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
myApp.directive('iso2symbol', function () {
return {
restrict: 'E',
replace: true,
link: function ($scope, $element, $attrs) {
var curIsoObj = $scope.$eval($attrs.curIso);
//this is object it may change
if (typeof curIsoObj !== 'undefined') {
console.log('not a text');
$scope.$watch('curIso', function (value) {
$scope.txt = value;
});
}else{
$scope.txt = $attrs.curIso;
}
},
template: '<div>---{{txt}}---</div>'
}
});
myApp.controller('MyCtrl', function ($scope) {
$scope.aModelVar = 'ModelVarText';
$scope.name = 'Superhero';
});