Вопрос

I want to create a single function that will be used for total project.

It will work based on the ng-model passed into it.

For ex:-

 $scope.checkBoxValueChanged=function(model) {
   if($scope.model=="AA") {
     $scope.model="BB";
   }
   else {
     $scope.model="BB";
   }
  };
});

If i have the passed model's value as "AA" then i need to assign the passed model's value as "BB"

But what i am getting is the model value instead of model name.

Can anyone tell me how to get the model instead of model value.

Any help will be highly appreciated.

Это было полезно?

Решение

You should pass the property name (what you refer to as "model") as a string parameter.
Then you can access it using the object[key] syntax.

$scope.checkBoxValueChanged = function(propName) {
    if($scope[propName] === 'AA') {
        $scope[propName] = 'BB';
    } else {
        $scope[propName] = 'AA';
    }
};

BTW, in JS, scope.model is equivalent to scope['model'], so the dot syntax won't work as you want it to.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top