1

I want to serve a page that already has data populated from PHP, and use AngularJS to edit and update this data, but initially I don't want to load the data into AngularJS.

Is there a way to disable data binding on load so that AngularJS doesn't replace the data that's already there, but enable it later when I edit some data and want to update the element?

tlenss
  • 2,609
  • 2
  • 22
  • 26
leninyee
  • 346
  • 1
  • 2
  • 7
  • That's very un-Angular-y, the purpose of Angular is data-binding. Any reason you're looking to do it this way? A better way would be to load the page, fire back a service and request your data, then display said data. – tymeJV Oct 04 '13 at 14:20
  • The reason is that this page is going to be cached, and I want to avoid any request to the API on page load, so the cached page needs to have all the data already. – leninyee Oct 04 '13 at 14:57

2 Answers2

1

May be you should to populate the template only using angularjs. Why would you want duplicate work by doing serverside templating and client side templating? I agree with @tymeJV. It is very un-Angular-y,

Or if you really want, you would want to have an init_function inside the angularjs controller that will be called only on edit and will load data when it does that. But I am not very convinced

Ranjith Ramachandra
  • 10,399
  • 14
  • 59
  • 96
  • I have an init function in place, but the problem is that AngularJS removes the data that's already in the HTML if there's no data loaded into the scope object. – leninyee Oct 04 '13 at 15:00
0

You can use the ng-init attribute. This post describes how you can use it.

Community
  • 1
  • 1
Thijs
  • 3,015
  • 4
  • 29
  • 54