0

I have a function defined in my controller that get's bound to an a element with ng-click, the li element in which the a element is nested also has an ng-repeat directive.
When I inspect the $scope of that controller through the angular chrome developer tools, I see that the function, in this case, $scope.goToApp is null.

I've done this a lot of other times in my other controllers, so to be sure that I didn't made any typos I've copy-pasted how I did it from another controller, but to no avail.

Controller:

(function () {
'use strict';

var controllers = angular.module('portal.controllers');

controllers.controller('applicationController',['$scope', 'ApplicationService', 'NavigationService','$rootScope', function ($scope, ApplicationService, NavigationService,$rootScope) {

    $scope.goToApp = function(appId){
        NavigationService.navigateToApp(appId, false);
    };

    $rootScope.ESS = ApplicationService.getApplications(Constants.id_ESS);
    $rootScope.SVF = ApplicationService.getApplications(Constants.id_SVF);
    $rootScope.MED = ApplicationService.getApplications(Constants.id_MED);

    $rootScope.$watch('ESS', function(newValue){
        $scope.ESS = newValue;
    });

    $rootScope.$watch('SVF', function(newValue){
       $scope.SVF = newValue;
    });

    $rootScope.$watch('MED', function(newValue){
       $scope.MED = newValue;
    });
}]);
}());

HTML:

<li data-ng-repeat="tool in ESS | filter: {tool:true} | orderBy:'description'" class="col-lg-12">
    <a class="toolLink" href="#" data-ng-click="goToApp({{tool.code}})">{{ tool.description }}</a>
</li>

Debugger:

goToApp: null
2
  • Remove curly braces from within: data-ng-click="goToApp(tool.code)" Commented Nov 29, 2013 at 9:47
  • thanks a lot, add it as an answer and I'll gladly accept it man :) Commented Nov 29, 2013 at 9:49

1 Answer 1

3

ngClick accepts an expression as a parameter. No need of using interpolation:

data-ng-click="goToApp(tool.code)"
Sign up to request clarification or add additional context in comments.

Comments

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.