vincentsty vincentsty - 1 year ago 134
AngularJS Question

$scope and setPristine() not working inside factory

I am trying to write convert my current api call into a factory which is reusable inside

factory. However, I can't seem to clear the form.

So, what i can i do to make the clearForm function work as it is.

<form name="formName">
<input type="name" ng-model="form.username"></input>
<input type="password" ng=model="form.password"></input>
<button type="submit" ng-click="submitForm()">Submit</button>

Answer Source

form is in $scope. You can't access it without using $scope and factory don't have $scope.

try like this


All you can do is to pass that form to service and clear it

'clearForm': function(formName) {

from controller