Angular ngresouce $ update不是一个函数

时间:2016-03-17 00:30:14

标签: angularjs x-editable ngresource

我正在使用angular xeditable来编辑字段并将其值更新到数据库但它无法正常工作。它一直说$ update不是一个功能。与$ save相同,这是一个POST。

不确定ng-repeat或xeditable是否正在创建一个范围问题,但是通过updateBusinessGoal函数传递的对象是已经更改的值,并且应该只需要调用更新。

HTML

<tr ng-repeat="goal in businessGoals.occupancyGoals | orderBy:'timeframe'">
     <td class="capitalize">{{goal.timeframe}}</td>
     <td>{{goal.current_value | number:0}}%</td>
     <td><a href="#" blur="sumbit" onaftersave='businessGoals.updateBusinessGoal(goal)' buttons="no" editable-text="goal.threshold">{{goal.threshold || 'empty'}}%</a></td>
</tr>

JS

businessGoals.updateBusinessGoal = function(goal){
    goal.$update({
        user_business_goal_id: goal.user_business_goal_id, 
        type: goal.type, 
        timeframe: goal.timeframe, 
        threshold: goal.threshold}
    );
}

return $resource(ENV.web_api_url + ENV.api_version + '/user/business_goals/:user_business_goal_id', {}, {
        update: {
            method: 'PUT',
            params: {
                user_business_goal_id: '@user_business_goal_id',
                type: '@type',
                timeframe: '@timeframe',
                threshold: '@threshold'
            },
            headers: {
                "X-Auth-Token": $window.sessionStorage.token
            }
        }
    })

1 个答案:

答案 0 :(得分:2)

对于那些偶然发现这一天的人来说,这是因为这是错误的语法。它应该像以下一样简单:

    businessGoals.updateBusinessGoal = function(goal){
        ServiceName.update(goal);
    );
}