0

This is my code.

$scope.sendFeedback = function ()  {

    var mobile1 = $scope.mobile;
    var feedback1 = $scope.feedback;

    var userfeedback = {
        mobile: mobile1,
        feedback: feedback1
    };

    var feedbackRef = firebase.database().ref("feedback/");
    var newFeedbackRef = feedbackRef.push();
    newFeedbackRef.set(userfeedback, function(error) {
        if (error) {
            alert ('Error while registering feedback.');
        } else {
            $scope.feedback = '';
            alert ('Your feedback is registered.');

        }
    });
}

After calling this function i can see alert ('Your feedback is registered.'); but $scope.feedback = '' not setting that particulat textField as empty. I tried $scope.feedback = null; also, but no luck.

what is wrong here?

Edit: HTML View added.

<md-input-container class="md-block">
    <label>Feedback</label>
    <input required="" name="feedback" ng-model="feedback" >
    <div ng-messages="projectForm.feedback.$error" role="alert">
     <div ng-message-exp="['required']">
        This field is required.
    </div>          </div>

</md-input-container>
4
  • can you post the html view ? Commented Sep 15, 2016 at 23:52
  • @Flint. added HTML view in question. Commented Sep 15, 2016 at 23:54
  • Possible duplicate of AngularJS: When to pass $scope variable to function Commented Sep 15, 2016 at 23:59
  • I m confused with what u actually want!!! Commented Sep 16, 2016 at 0:05

3 Answers 3

1

I encountered that kind of problem several times, and solved it using the following workaround :

    angular.element(document.getElementById('doc'))
     .scope().$apply( function() {
            $scope.feedback=''
     )}

I made that very minimal working example, for the sake of testing the SO's snippet runner, and mostly using your own code. Hope this helps.

<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>

<script>
  var module=angular.module('test',[]).controller('test', function($scope) 
{
    $scope.click = function() {
            $scope.feedback = '';
            alert ('Your feedback is registered.');
    }
})
</script>
</head>
<body>

<div ng-app="test" ng-controller="test" id='feedback'>
<md-input-container class="md-block">
    <label>Feedback</label>
    <input required="" name="feedback" ng-model="feedback" >
    <div ng-messages="projectForm.feedback.$error" role="alert">
     <div ng-message-exp="['required']">
        This field is required.
    </div>          </div>

   <button ng-click='click();'>click?</button>
</md-input-container>
  </div>

Sign up to request clarification or add additional context in comments.

Comments

1
$scope.feedback = [];

(or)

setTimeout(function () {
    $scope.$apply(function () {
        $scope.feedback = [];
    });
}, 1000);

Comments

0

Do you have ng-app and ng-controller set? I tested your code on my machine, and it works as long as you have the app and controller set up. Can you make a JSFiddle?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.