Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-click with data-toggle

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>
like image 503
JenuRudan Avatar asked Dec 26 '15 23:12

JenuRudan


1 Answers

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;
}
like image 141
Ignacio Chiazzo Avatar answered Sep 27 '22 21:09

Ignacio Chiazzo