【发布时间】:2015-06-12 22:47:55
【问题描述】:
我一辈子都想不通为什么我不能在我的控制器中调用这个函数。
单击accordion-group 属性时出现此错误:Uncaught ReferenceError: getConversationsForUser is not defined
这里是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>
这是正在使用的控制器(部分代码):
controller('convCtrl', ['$scope', 'messageFactory', function ($scope, messageFactory) {
var currentUser = helpers.storage.get('UID');
$scope.contacts = [];
$scope.getContacts = function () {
/*Does stuff*/
};
//This is the function it is trying to call
$scope.getConversationsForUser = function (userUID) {
/*Does stuff*/
};
//Setup
$scope.getContacts();
}]);
我尝试将 onclick 更改为不同的元素,而是调用 getContacts 函数,但我总是得到 Uncaught ReferenceError
我知道该函数在我的范围内,因为我正在将 contacts 变量数据绑定到页面。
【问题讨论】:
-
因为它是在你的 $scope 上定义的,而不是在 onclick 需要的全局空间中,你想要
ng-click
标签: javascript html angularjs scope