css - Apply text to hover based on condition in AngularJS -


how can select specific text appear in hover based on logic using angularjs? example, have value , if class equals 'warning' want specific hover message, if class equals 'success' want different hover message appear.

my logic write function says if color = success hover = this, if color = warning hover = that, if color = error hover = else. advice?

      getcolor = function() {              var data = 88;                if(data < 75){                  return "losses-success";              }else              if(data >=75 && data < 90){                  return "losses-warning";              }else              if(data > 90){                  return "losses-error";              }          };
.losses-success{      display: inline-block!important;      width: 8px;      height: 20px;      background-color: green;  }  .losses-warning{      display: inline-block!important;      width: 8px;      height: 20px;      background-color: yellow;  }  .losses-error{      display: inline-block!important;      width: 8px;      height: 20px;      background-color: red;  }
<div id="ctotal" class="losses-tooltip" ng-class="getcolor()">    <span class="tooltiptext"> </span>    <span class="block"><sup>$</sup>      <strong class="amount">{{loss}}</strong></span>  </div>

if classes , messages fixed, think it's better return object class , message:

return {      ngclass: "losses-success",      message: "some text" } 

than can use class property in ng-class , show message related property.

<div id="ctotal" class="losses-tooltip" ng-class="getcolor().ngclass">      {{getcolor().message}} </div> 

i don't approach much, because getcolor() function called on every angular cycle. , getcolor().ngclass syntax seems weird me.

i prefer set object in controller, , update values when it's needed. if can't control when class , message updated, can choose first approach. if able control this, can simply:

function getcolor(value) {     //put logic     //     $scope.myobj = {          ngclass: "anyclass",          message: "any message"     } } 

and in template:

<div id="ctotal" class="losses-tooltip" ng-class="myobj.ngclass">      {{myobj.message}} </div> 

note in second approach need call getcolor function update values in myobj, have better performance.

in first approach function called on every cycle, values updated every time (you don't need call function explicitly in controller update value). so, in case need careful performance of application.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -