Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<script type="text/ng-template" id="template1">
{{symbolsLength()}} {{x1()}} {{x2()}}
</script>
<script type="text/ng-template" id="template2">
static html
</script>
<input ng-model="model.symbols" />
<button ng-click="click()">Change Template</button>
<hr>
<ng-include src="model.templateName"></ng-include>
</div>
JavaScript
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.model = {
symbols: 'три',
templateName: 'template1',
calls: 0
};
$scope.click = function() {
$scope.model.templateName = ($scope.model.templateName == 'template1') ? 'template2' : 'template1';
};
var callsNum = 0;
$scope.symbolsLength = function() {
console.log('symbolsLength() calls: %d', ++callsNum);
return $scope.model.symbols.length;
};
$scope.x1 = function() {
return $scope.symbolsLength()+'x1';
};
$scope.x2 = function() {
return $scope.symbolsLength()+'x2';
};
}