I am interested in finding the best way to store values in Angular 1 without relying on $scope, as it will no longer be used in Angular 2. I want to start transitioning to newer practices in preparation for the next generation of Angular.
Here is an example of some HTML code:
<span ng-click="axArgicSearch.replace(part.euroCode)"
class="btn btn-xs btn-info glyphicon glyphicon-refresh"
></span>
and the corresponding function:
replace: function(partId) {
return api.glass.selectParts(partId, caseManager.data.id);
}
I would like to dynamically change the class of the span element when a button is clicked.
One possible approach using $scope:
<span ng-click="axArgicSearch.replace(part.euroCode)"
ng-class={ 'btn btn-xs btn-info glyphicon glyphicon-refresh': $scope.part.euroCode.isSelected,
'other-class': !$scope.part.euroCode.isSelected }">
></span>
and then adjust the function accordingly:
replace: function(partId) {
$scope.partId.isSelected = true;
return api.glass.selectParts(partId, caseManager.data.id);
}
This is just a sample and has not been tested for functionality.
Is there a way I can achieve this without using $scope?