简体   繁体   中英

how do I put variable in an angular factory

Hello (kind of a greenhorn question),

i have the following:

 $scope.updateInline = function(fctr, item, fieldName){

        var obj = {};
        obj[fieldName] = item[fieldName];
        obj['id'] = item.id;

        [fctr]update( {id:item.id}, obj, function (data) {

            if (!data.error) {
                notify({ messageTemplate: $scope.notifyMsg.UpS, classes: 'alert-success', duration: 3000});
            } else {
                notify({ messageTemplate: $scope.notifyMsg.UpE, classes: 'alert-danger', duration: 3000});
            }

        });

    };

in my html:

 <input type="text" ng-model="item.clientId" ng-ng-change="updateInline('Invites_Fctr',item, 'clientId')" />

how do I pass the Invites_fctr from the html to the [fctr] on the .update function

the [fctr]update(....) is not working. my syntax is not good.

I hope this is clear. thank you

I don't know why exactly you want to do this, but you might try saving the factory as a scope property:

var factories = {"Invites_Fctr": InvitesFactory, "List_Fctr": ListFactory}; //Assuming they are properly injected onto the controller.
$scope.updateInline = function (factoryName, item, fieldName) {
    var obj = {};
    obj[fieldName] = item[fieldName];
    obj['id'] = item.id;
    factories[factoryName].update({id: item.id}, obj, function (data) {
        if (!data.error) {
            notify({messageTemplate: $scope.notifyMsg.UpS, classes: 'alert-success', duration: 3000});
        } else {
            notify({messageTemplate: $scope.notifyMsg.UpE, classes: 'alert-danger', duration: 3000});
        }
    });
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM