javascript - AngularJS ngClick to fire a service but doesn't -
i have following inside directive
scope.actions = { getsearch: searchresultpageservice.getsearch(scope.keywords, scope.settings) };
the template follows
<button class="btn btn-primary" type="button" data-ng-click="actions.getsearch()">send</button>
in service i'm checking see if scope.keywords
, scope.settings
passed through using console.log there no output.
what doing wrong ngclick usage
(function () { 'use strict'; angular .module('app.search') .factory('searchresultpageservice', [ '$timeout', function ($timeout) { var $module = { getsearch: function(keywords, settings){ console.log(keywords); console.log(settings);
scope.actions.getsearch
result returned calling searchresultpageservice.getsearch
, rather function itself.
you either need pass reference function view:
scope.actions = { getsearch: searchresultpageservice.getsearch };
and modify view's click handler follows:
<button class="btn btn-primary" type="button" data-ng-click="actions.getsearch(keywords, settings)">send</button>
or create new anonymous function sent view:
scope.actions = { getsearch: function() { searchresultpageservice.getsearch(scope.keywords, scope.settings); } };
in case view code stays same. choose second option there.
Comments
Post a Comment