new to angular here :)
I have a custom directive that have an ng-click in it which calls a function I have defined in a controller (not the directive controller).
This is the html view:
<course-pass course-id="bla"/>
This is the directive:
scotchApp.directive("coursePass", function($compile) {
return {
restrict: "E",
controller: 'dropdownCtrl',
replace:'true',
templateUrl: 'template/coursepass.html',
scope: {
courseId: '@courseId',
}
}
});
This is coursepass.html (the template):
Important line is the li tag
<div class="btn-group courseContainer" dropdown>
<button type="button" class="btn dropdown-toggle course passedCourse" dropdown-toggle ng-disabled="disabled" id="{{courseId}}">
some name<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a ng-click="markFail({{courseId}})">mark fail</a></li>
</ul>
</div>
And this is the function inside the dropdownCtrl controller:
$scope.markFail = function(courseId) {
alert("we do nice things");
// do some stuff
}
The function renders well, and so does {{courseId}}
But I get this error:
Error: [$parse:syntax] http://errors.angularjs.org/1.2.25/$parse/syntax?p0=courseId&p1=is%20unexpected%2C%20expecting%20%5B%3A%5D&p2=12&p3=markFail(%7B%7BcourseId%7D%7D)&p4=courseId%7D%7D)
at Error (native)
On angular site it says:
Syntax Error: Token 'courseId' is at column {2} of the expression [{3}] starting at [{4}].
And the ng-click wont trigger the function.
When I change the temeplte to read something like:
<li><a ng-click="markFail(someString)">mark fail</a></li>
I can see that the on-click works and calls markFail function, but the parameter passed is undefined.
What am I doing wrong?
Thank you!
markFail("someString"). Note the added quotes. This should work. If it does,markFail(courseId)should work too. If that doesn't, thencourseIdisnt being set properly somewhere.