angularjs - using ng-class on keyup function value -
i trying accomplish simple valid toggle on outcome of keyup function. basically, input keyup action triggers function. stuff, returns true or false. upon this, css class of span near input should changes. missing in ng-class? have searched similar topic still couldn't overcome problem.
html code:
<div ng-repeat="drug in inputdrugs track $index"> <label>type drug name</label><br/> <input ng-keyup="getrxcui(medvalue, $index)" ng-model="medvalue" placeholder="something advil" /> <span class="alert alert-danger" role="alert" ng-class="{'alert alert-success': getrxcui(medvalue, $index)}">?</span> </div>
in controller.js:
$scope.getrxcui = function(medvalue, index){ var rxcui = '', url = 'blabla' + medvalue; $http.get(url). success(function(data, status){ try { // code here goes here , then.. return true } catch(err) { // if value not correct: return false } }). error(function(data, status){ // called asynchronously if error occurs // or server returns response error status. console.log('error receiving data: ' + status); console.error(data); }); }
i have managed to jquery, point me keep angular code clean. appreciated, thanks.
for one, don't need "override" class can have one. anyhow, problem returning value promise, , it's meaningless.
also, have associate status of request loop iterator first change markup this:
<input ng-keyup="getrxcui(drug, medvalue, $index)" ...
now have span:
<span role="alert" ng-class="{'alert alert-success': drug.rxcuistatus == 'success', 'alert alert-danger': drug.rxcuistatus == 'failure'}">
and in function:
$scope.getrxcui = function(drug, medvalue, index){ var rxcui = '', url = 'blabla' + medvalue; $http.get(url). success(function(data, status){ try { // code here goes here , then.. drug.rxcuistatus = 'success'; } catch(err) { // if value not correct: drug.rxcuistatus = 'failure'; } }). error(function(data, status){ // called asynchronously if error occurs // or server returns response error status. console.log('error receiving data: ' + status); console.error(data); drug.rxcuistatus = 'failure'; }); };
Comments
Post a Comment