0

I get an error in my developer console as such:

Error: [$parse:syntax] http://errors.angularjs.org/1.6.5/$parse/syntax?p0=%7B&p1=invalid%20key&p2=43&p3=GetTimelineByUserIdAndProjectId(u.UserId%2C%7B%7BselectedProject.Id%7D%7D)&p4=%7BselectedProject.Id%7D%7D)

angular

$scope.GetTimelineByUserIdAndProjectId = function (userId, projectId) {
   alert(userId +"-"+projectId);
}

HTML

<div class="active tab-pane" id="view_projects">
<div>
    <form class="form-inline">

        <select ng-model="selectedProject" class="selectpicker" data-live-search="true"
                ng-options="s.Description for s in allProjects track by s.Id"
                ng-change="getProjectsByUserId(selectedProject.Id)"
                select-picker></select>

        <select ng-model="selectedDeveloper" class="selectpicker" data-live-search="true" ng-options="u.ID as u.FullName for u in allUsers" select-picker></select>
    </form>
</div>
<br/>
<div >
    <div class="panel panel-default" style="width:25%" ng-show="showUserTable">
        <div class="panel-body">
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>Developers for {{selectedProject.Description}}</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="u in usersByProjectId">
                        <td ng-click="GetTimelineByUserIdAndProjectId(u.UserId,{{selectedProject.Id}})"><a href="javascript:void(0);"> {{u.Developer}}</a></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

I should be able to get the "alert" when I click on the list. If I just get the u.userId I am actually able to get the alert with the value but when I add the {{selectedProject.Id}} that's when I get the error.

2
  • Why did you add the expression brackets ({{ }}) around selectedProject.Id but not u.UserId? Expressions aren't valid as function parameters, remove the brackets and it should work. The fact that u.UserId worked without them should be a strong clue that they aren't needed / won't work. Commented Dec 7, 2017 at 2:10
  • Oh! I see. I was thinking that using expression without bracket only works if it is directly inside the ng-repeat. Now I know. Thank you. Commented Dec 7, 2017 at 2:15

1 Answer 1

1

Inside ng-click you don't need to put interpolation because you are already entering expression. We give {{interpolation}} to write expressions in HTML. In your case ng-click is already an expression so it you don't need that {{}} there in ng-click. you give GetTimelineByUserIdAndProjectId(u.UserId,selectedProject.Id)

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

1 Comment

Pleasure is mine!!

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.