ng if with angular for string contains

前端 未结 5 992
盖世英雄少女心
盖世英雄少女心 2020-12-30 19:55

I have the following Angular code:

  • {{new.label}}
  • 5条回答
    •  旧时难觅i
      2020-12-30 20:16

      Do checks like that in a controller function. Your HTML should be easy-to-read markup without logic.

      Controller:

      angular.module("myApp")
      .controller("myController",function(){
          var self = this;
      
          self.select = { /* ... */ };
      
          self.showFoo = function() {
              //Checks if self.select.name contains the character '?'
              return self.select.name.indexOf('?') != -1;
          }
      });
      

      Page example:

      Bar

    提交回复
    热议问题