0

C# MVC App using AngularJS

I am trying to display a list of values in a table that were originally entered in a text area.

Here is the workflow

User enters values in a text area as

A
B
C

When the user clicks on a button a modal window opens and should display A B C in a table .

I am trying to use angular to do this. I have tried the following:

<a class="btn btn-inverse pull-right" ng-click="arrangelist()">Arrange list</a>

<textarea id="letterlist" ng_model="letters"></textarea>

Also tried

@Html.TextAreaFor(model => model.letters, new { ng_model = "letters", @class = "width-100-percent", @rows = "7" })

And here is my modal window:

<div id=" arrangelist" class="modal hide fade" aria-hidden="true">
    <table class="table">
        <thead>
            <tr>
                <th>Letters</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-animate="'table-anim'" ng-repeat="letter in letters">
                <td>{{letter}}</td>
           </tr>
        </tbody>
    </table>
    <button type="button" class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>

Here is the JavaScript that opens the window:

$scope. arrangelist = function() {
    return $('#arrangevideos').modal('show');
}

So the modal window opens and displays the table but no values are inside the table.

How can I pass the values from the text area to the table in the modal window using Angular

2 Answers 2

1

Change ng_model = "letters" to ng-model = "letters".

And letters should be an array instead of string. You have to split the input to list of strings.

$scope.arrangelist  = function() {
    var letterplits;
    letterplits = $('#letterlist').val().split('\n');
    $scope.letters = letterplits;
    return $('#arrangelist').modal('show');
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thats an oversight by me. I changed it but the values from the text area still doesnt populate the table in the modal window
@Milligran The problem could be letters needs to be an array, you have to split the string typed in
Thanks. Thats it. converted to array
0

you need to use ng-model, not ng_model. As long as your modal is in the same controller as your textarea, you should be able to pass it. Also, you have a space between $scope. and arrangelist. See this fiddle for a simple working example.

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.