Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  89] [ 4]  / answers: 1 / hits: 23327  / 9 Years ago, sat, december 26, 2015, 12:00:00

I have a list item which toggles modal and sets a param using ng-click
the problem is when calling a function in any other place which logs Course.SelectedCourse it's undefined although Course.ID has a value.



<li class=facebook style=width:33%;>
<a ng-click=Course.SelectedCourse = Course.ID data-toggle=modal data-target=#myModal>
<span class=glyphicon glyphicon-user></span>
</a>
</li>

More From » angularjs

 Answers
5

Use a function in the controller, this might look like this :



In the view :



<li class=facebook style=width:33%; >
<a ng-click=setSelectedCourse(Course.ID) data-toggle=modal data-target=#myModal>
<span class=glyphicon glyphicon-user></span>
</a>
</li>


In the controller



function setSelectedCourse(course_id){
$scope.Course.SelectedCourse = course_id;
}

[#63936] Wednesday, December 23, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaidyn

Total Points: 633
Total Questions: 102
Total Answers: 100

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;