I am new to using Angular and CoffeeScript in combination, integrating it into a Rails project. My goal is to create a function within the controller that triggers upon clicking a button in the view.
Below is the HTML markup:
<div id="labs">
<div class="clients" ng-repeat="client in clients" ng-class="{first: $index == 0}">
<h1>{{client.name}}</h1>
<div class="labs">
<ul>
<li ng-repeat="lab in client.labs">
<a ng-href="/#!/labs/{{lab.id}}/process">
<button ng-click = "test()">Test</button>
<span>{{lab.name}}</span>
<span>{{lab.created_at | date:'MMMM yyyy' }}</span>
</a>
</li>
</ul>
</div>
</div>
</div>
This is the relevant Controller code:
angular.module("deloitte").controller('labsCtrl', ['$scope', 'labService','labPreferencesService', ($scope, labService, labPreferencesService ) ->
labService.query (data) ->
$scope.clients = data
# console.print (clients)
$scope.test -> console.log("Hello!");
])
The error message being displayed is:
angular.js?body=1:5755 TypeError: $scope.test is not a function
at new <anonymous> (labsController.js?body=1:7)
at invoke (angular.js?body=1:2903)
at Object.instantiate (angular.js?body=1:2915)
at angular.js?body=1:4806
at update (angular.js?body=1:14199)
at Object.Scope.$broadcast (angular.js?body=1:8308)
at angular.js?body=1:7464
at wrappedCallback (angular.js?body=1:6847)
at wrappedCallback (angular.js?body=1:6847)
at angular.js?body=1:6884
I have verified the syntax and it seems correct. Even attempting `=->` still results in an error. Any assistance would be greatly appreciated.