There is a lot to be learned from the most up-voted angular question on stack overflow:
"Thinking in AngularJS" if I have a jQuery background? The quote that is most applicable to your question comes from Mark Rajcok's answer:
In jQuery, selectors are used to find DOM elements and then bind/register event handlers to them. When an event triggers, that (imperative) code executes to update/change the DOM.
In AngularJS, you want to think about views rather than DOM elements... Views are tied to models (via scopes). Views are a projection of the model. Events change models (that is, data, scope properties), and the views that project those models update "automatically."
In AngularJS, think about models, rather than jQuery-selected DOM elements that hold your data. Think about views as projections of those models, rather than registering callbacks to manipulate what the user sees.
Rather than write a function to replace html inputs with labels, I will offer some alternatives that have the same effect, in an angular way.
1. Use ng-if
to toggle inputs and labels:
<table>
<tr>
<td>Temp:</td>
<td ng-if="!aaa">
<input ng-model="bbb" />
</td>
<td ng-if="!aaa">{{bbb}}</td>
<td ng-if="aaa">{{nn.vs.temp}}</td>
</tr>
</table>
2. Use ng-include
to display different templates:
<div ng-if="aaa" ng-include="'readonly.html'"></div>
<div ng-if="!aaa" ng-include="'update.html'"></div>
3. Use a directive to conditionally construct the elements:
app.directive('updateToggle', function() {
return {
restrict: 'A',
replace: true,
scope: {
editvalue: '=',
readvalue: '=',
delivered: '='
},
template: '<td>\
<span ng-show="!delivered">\
<input ng-model="editvalue"> {{editvalue}}\
</span>\
<span ng-show="delivered">\
{{readvalue}}\
</span>\
</td>'
}
});
...
<td>Temp:</td>
<td update-toggle delivered="status.aaa" readvalue="nn.vs.temp" editvalue="data.bbb"></td>
I think you will find that strategies like this are more flexible than trying to parse and reconstruct html snippets in a function. What if the input was a textarea, a list of radio buttons, an editable div, a drop-down list with multiple options, or even a custom directive? With the angular approach, these are all equally easy to switch out for something else.
Here is a demo: http://plnkr.co/edit/BHukpPrcauZn9OI9DMRs?p=preview