Using page’s angular JS in chrome extension

Hmm.. Actually you should be just able to change the value using vanilla Javascript or JQuery and should not need to update the scope as it is two-way binding ie. Updating the view updates the model and vice-versa.

The only reason why the model does not update is because the watchers to update the model trigger only on particular events like “click” or “input”.

So the solution here would be to manually trigger these events.
This can be do by:

// the selector used is based on your example.
var elementTOUpdate = $('.textbox');
input.val('new-value');
input.trigger('input');

The last statement will trigger all the handlers on the element for the “input” event ( which will fire the angular watchers ) and update the scope.
More info on the trigger function:
http://api.jquery.com/trigger/

Leave a Comment