javascript - AngularJS call function from click -
i can't life of me figure out why can't call function in controller.
on clicking accordion-group
attribute error:
uncaught referenceerror: getconversationsforuser not defined
here html:
<ui-view id="smtconvocard" layout="column" layout-fill layout-padding> <div layout="row" flex layout-align="center center"> <md-card flex-gt-sm="90" onresize="resize()" flex-gt-md="80"> <md-card-content> <md-list> <h2>conversations</h2> <accordion close-others="oneatatime"> <accordion-group heading="{{contact.firstname}} {{contact.lastname}}" ng-repeat="contact in contacts" onclick="getconversationsforuser(contact.useruid)"> <div>test</div> </accordion-group> </accordion> </md-list> </md-card-content> </md-card> </div> </ui-view>
here controller being used (partial code):
controller('convctrl', ['$scope', 'messagefactory', function ($scope, messagefactory) { var currentuser = helpers.storage.get('uid'); $scope.contacts = []; $scope.getcontacts = function () { /*does stuff*/ }; //this function trying call $scope.getconversationsforuser = function (useruid) { /*does stuff*/ }; //setup $scope.getcontacts(); }]);
i've tried changing onclick
different element, calling getcontacts
function instead , uncaught referenceerror
i know function within scope because i'm data binding contacts
variable page.
try :
<accordion-group heading="{{contact.firstname}} {{contact.lastname}}" ng-repeat="contact in contacts" ng-click="getconversationsforuser(contact.useruid)"> <div>test</div> </accordion-group>
and don't forget insert ng-controller="convctrl"
in element wrapping accordion
.
update
i add little explanation : $scope in controller mysupercontroller
have linked in dom via ng-controller="mysupercontroller"
attribute added tag (= dom element), $scope variable represent variable within controller.
as create function attached scope ($scope.myfunction = function () { /* ... */ }
), can call it, i.e., when event fired. case via ng-click
directive attaches event handler element on it's set attribute.
Comments
Post a Comment