0

I use an input text to put text in div. When I write something in the input and I press the key Enter, the text from the input field is added to a div just below and normally, an array should be updated in my controller with the new value. I don't know how can I get the list of element text added to the div from a controller.

I'm trying to use the property n-change on my div with ng-model but it doesn't work.

 <div class="row center" id="searchD" >
    <form id="search" >
        <input type="text" id="searchInput" onchange="createTag($(this).val());"/>
    </form>
  </div>
  <div class="row center" ng-controller="Mainctrl">
    <div id="tagContainer" ng-model="tagList" ng-change="tagList()">
    </div>
  </div>

2 Answers 2

1

You could do it something like below if that is what you are expecting.

Html :

    <div class="row center" id="searchD" ng-controller="Mainctrl">
        <form id="search" >
            <input type="text" id="searchInput" ng-model="tagInput" ng-change="addTag()"/>
        </form>
    </div>
    <div class="row center">
        <div id="tagContainer" ng-repeat="tag in tagList">{{tag}}
        </div>
    </div>

Mainctrl:

    $scope.tagList = [];

    $scope.addTag = function () {
        $scope.tagList.push($scope.tagInput);
        $scope.tagInput = '';
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Are you asking how to get data from the controller onto the html page? If so, you just use angular interpolation {{ someData }}

<div id="tagContainer" ng-model="tagList" ng-change="tagList()">
  {{ tagList }}
</div>

1 Comment

In addition, if the data is an array you can also iterate over the array using the ngRepeat directive. ng-repeat="tag in tagList" and access each tag with {{ tag }}

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.