我有一个$resource其 API 将始终返回一些需要在进入表示层之前清理的数据。具体来说,它是 .NET 以可爱的'/Date(...)/'格式返回 Date 对象。
我不想每次打电话.query()或.get(). 是否有某种方法可以通过在更新实例属性的 REST 方法上调用的回调来扩展资源,或者通过添加某种$watch在日期属性更改时触发的回调?基本上每个 this 实例都会发生一些事情$resource。
angular.module('myAppServices', ['ngResource'])
    .factory('Participant', ['$resource', function ($resource) {
        var res = $resource('api/url/participants/:id', { id: '@id' });
        // This obviously doesn't work, but something kinda like this?
        res.prototype.$watch(this.FieldName, function(newVal, oldVal) {
            if (needsCleaning(newVal.fieldName) {
                this.FieldName = cleanupField(newVal);
            }
        };
    });