-1

I have a text box that passes the user input into a $scope. I need to pass this further along into a firebase query, but im having trouble getting the variable to register the input stored in $scope. Code:

  $scope.array = [];

$scope.addListItem = function(quote){
$scope.array.unshift(quote);
console.log(quote)
this.customQuote = null;
};

  var prefix = 'tags/'
  var userInput = console.log($scope.array)

  var search = prefix + userInput


  firebase.database().ref('products').orderByChild(search).equalTo(true).once('value', function(products)

And the html:

<form ng-submit="addListItem(customQuote)" name="customQuoteForm">
          <div class="item item-input-inset">
            <label class="item-input-wrapper">
              <input type="text" placeholder="placeholder content" ng-model="customQuote" required> 
            </label>
            <button class="button button-small" ng-disabled="customQuoteForm.$invalid">
              Submit
            </button>
          </div>
        </form>

Thanks in advance!

1
  • What do you have on the html? Commented Dec 13, 2016 at 3:02

2 Answers 2

0

Whatever you name the model in the html, you need to name it in the javascript.

I see you named it ng-model="customQuote". So you should access it as $scope.customQuote in the javascript.

Also you are initializing the model as null. Don't do that, instead declare it like this:

 $scope.customQuote = "";
Sign up to request clarification or add additional context in comments.

4 Comments

The example actually works fine as far as passing data from the form into the array, however, I cant get it back out to use in a variable. for instance the 'console.log(quote)' returns the value from the text input. Am I still missing something?
@MacD You don't need to have two customQuotes. The one in the ngModel is fine. No need to add another in the submit method.
using null is irrelevant
Yes it did, however, I don't think it answers my question. I am trying to use the value in $scope.addListItem. I need to combine it with the search variable so I can use it in the firebase query.
0

Solved it by simply moving the variable and firebase query inside the function..

      $scope.addListItem = function(quote){
      $scope.array.unshift(quote);
      console.log(quote)
      var tag = quote
      var text = 'tags/'

      var search = text + tag
      console.log(search)

      firebase.database().ref('products').orderByChild(search).equalTo(true).once('value', function(products) {};

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.