Thursday, July 31, 2014

AngularJS: dynamically assign parameter for $scope

I need to have dynamic parameters assigned for $scope after getting data from server.

I think it is common since angularJS directives often need it for condition check etc.

so I defined a function then being called within success{} closure as below:
$scope.updateAllxxxSelect= function(obj) {

    $(obj).find("input:checked").each(function (i, ob) {
        var t = $(ob).val();
        //This is the line
        $scope[t] = true;
    });

    $(obj).find("input:not(:checked)").each(function (i, ob) {
        var t = $(ob).val();
        //This is the line
        $scope[t] = false;
    });
   
};

No comments:

Post a Comment