There is a way to update a value in object and my view (HTML) display the new value without use two way bind with Angular 1.5.3?
Asked
Active
Viewed 55 times
0
-
Have you checked http://stackoverflow.com/questions/18790333/render-value-without-data-binding – Chinni Jun 02 '16 at 18:53
-
@Chinni Yeah. I already saw this thread. But my case I something different between because I need to update in view but only when my model change. So If I really understand angular-once or bindOnce directive just update one time (at DOM creation) and no more. Is it right? – Leonan Luppi Jun 02 '16 at 18:58
-
@LeonanLuppi yeah that's correct, so you need a one-way binding from controller to view but not the other way around? That's just standard [ng-bind](https://docs.angularjs.org/api/ng/directive/ngBind) – Robin-Hoodie Jun 02 '16 at 18:59
-
@NexusDuck But standard ng-bind makes watcher I'm trying to avoid watcher. – Leonan Luppi Jun 02 '16 at 19:06
-
@LeonanLuppi Can you give an example of what it is you want to achieve? – Robin-Hoodie Jun 02 '16 at 19:10
-
@Leonan Luppi: If you want to change the DOM value once the value in controller changes without two way bind, then you can go ahead with native JS using `document.getElementById()` function to update the DOM from controller. – Chinni Jun 02 '16 at 19:18
-
@NexusDuck http://jsfiddle.net/988DP/508/ – Leonan Luppi Jun 02 '16 at 19:20
-
@NexusDuck image that I have many $scope.obj . This is generate many watchers in my app. – Leonan Luppi Jun 02 '16 at 19:27
-
angular 1.5 introduced one-way binding with the `<` scope expression https://docs.angularjs.org/api/ng/service/$compile#-scope- – Daniel Lizik Jun 02 '16 at 19:34
-
@Daniel_L yeah but how can I use in scope ? I think this is just for directive scope definitions. Following my example: http://jsfiddle.net/988DP/508/ how can I use ? – Leonan Luppi Jun 02 '16 at 19:38
-
@LeonanLuppi hard to say without a concrete example and no code. – Daniel Lizik Jun 02 '16 at 19:39
-
@Daniel_L here it's a concrete example: http://jsfiddle.net/988DP/508/ – Leonan Luppi Jun 02 '16 at 21:07
-
@LeonanLuppi I updated my answer with what I think you need – Robin-Hoodie Jun 03 '16 at 04:52
1 Answers
0
If I understand you correctly you need a one-way bind from your controller to your view. If so, you can just use ng-bind
E.g.
{{ctrl.myName}}
or <span ng-bind="ctrl.myName"></span>
If you want a one-time bind, this was introduced in angular 1.3:
E.g.:
{{::ctrl.myName}}
binds myName
once, future changes to it won't be picked up

Robin-Hoodie
- 4,886
- 4
- 30
- 63