1

I am using angular to build a table for me dynamically. The Expression user.User.id needs to be listed out as an integer in each place that I use it and it works everywhere except inside a html script tag that I am using. There it throws an error in javascript. I'm sure there is a better way to do what I'm doing here, but I'm looking for a quick and simple solution to display the user id so that it can be referenced by the script tag.

Here is the code:

 <table class="table" ng-hide="loading" >

        <tr>
            <th>Test Search Code</th>
            <th>Test Current Company</th>
            <th>Name</th>
            <th>Email</th>
            <th>Created</th>
            <th></th>
        </tr>

        <tr ng-repeat="user in users | filter:searchText ">
            <!-- THESE REFERENCES WORK FINE -->
            <td>{{user.User.mapped_test_search_code}}</td>
            <td>{{user.Employment[0].name}}</td>
            <td>{{user.User.mapped_first_name}}</td>
            <td>{{user.User.mapped_email}}</td>
            <td>{{user.User.created}}</td>
            <td><a href="/admin/mapped_users/edit/{{user.User.id}}"><span class="glyphicon glyphicon-pencil"></span></a></td>

            <td>

                <!-- THIS ONE WORKS TOO-->
                <form action="{{'/admin/users/delete/' + user.User.id}}" name="post_{{user.User.id}}" id="post_{{user.User.id}}" style="display:none;" method="post" class="ng-pristine ng-valid">
                    <input type="hidden" name="_method" value="POST">
                </form>

                <!-- THIS ONE IN THE A TAG, IN THE SCRIPT ATTRIBUTE DOES NOT WORK -->
                <a href="#" class="btn btn-block" onclick="if (confirm(&quot;Are you sure?&quot;)) { document[ 'post_' + user.
                User.id ].submit(); } event.returnValue = false; return false;" original-title="">
                    <span class="glyphicon glyphicon-trash"></span>
                </a>

            </td>

        </tr>

    </table>
3
  • Use ng-click="yourFunction()", and $scope.yourFunction = function() { /* whatever */ } Commented Aug 18, 2014 at 16:17
  • 1
    You should use ng-click and move the confirmation logic into a function in controller. Commented Aug 18, 2014 at 16:17
  • Yeah, your javascript there should not be inline, it should be in a js file... like in your controller. Commented Aug 18, 2014 at 18:47

0

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.