I'm adding a mild amount of angularjs to my existing application. I'm starting with utilizing controllers to manage my forms which are all submitted by ajax. The forms are currently pulled into the page using jQuery's $.load()
function and the form elements already have values.
I'd like my models I've assigned into $scope to have these values available. For example:
<form>
<input type="text" ng-model="user.firstName" value="Gregg" />
<input type="text" ng-model="user.lastName" value="Bolinger" />
<button ng-click="update(user)">Save</button>
</form>
And then in my main.js file I would have something like the following:
function UserCtrl($scope) {
$scope.update = function(user) {
// update the user
};
}
As is, my form input elements are blank because the ng-model is empty. Is there a way to initialize my ng-model with the existing values in the form?
BTW, I did read this SO Question which is the same as mine, however, I'm hoping for a better answer than some window scoped global variable.