Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 是否可以在ngClass中传递html属性?_Css_Ionic Framework_Svg_Attributes_Ionic4 - Fatal编程技术网

Css 是否可以在ngClass中传递html属性?

Css 是否可以在ngClass中传递html属性?,css,ionic-framework,svg,attributes,ionic4,Css,Ionic Framework,Svg,Attributes,Ionic4,我使用的是Ionic,在myComponent.html文件中有一个svg路径,如下所示: <path id="US" (click)="countryNameDetails($event)" title="United States" [ngClass]="{'BEEN' : array.indexOf('United States') !== -1, 'NOTBEEN' : array.indexOf('United States) === -1 }".../> 该路径根

我使用的是Ionic,在myComponent.html文件中有一个svg路径,如下所示:

 <path id="US" (click)="countryNameDetails($event)" title="United States" [ngClass]="{'BEEN' : array.indexOf('United States') !== -1, 'NOTBEEN' : array.indexOf('United States) === -1 }".../>

该路径根据单词是否在我的数组中而更改CSS类。这个单词基本上与每个路径的标题相同,我不想继续写标题名。在我的ngClass中,我是否可以在路径中传递title属性…我已经尝试了我能想到的一切


谢谢

您可以将模板引用变量添加到svg路径并访问title属性

<path
  title="United States"
  [ngClass]="{'BEEN': array.indexOf(path.title) !== -1, 'NOTBEEN': array.indexOf(path.title) === -1 }"
  #path
/>

我更喜欢这种语法:

<path
  title="United States"
  [ngClass]="array.includes(path.title) ? 'been' : 'not-been'"
  #path
/>

您可以将模板引用变量添加到svg路径并访问title属性

<path
  title="United States"
  [ngClass]="{'BEEN': array.indexOf(path.title) !== -1, 'NOTBEEN': array.indexOf(path.title) === -1 }"
  #path
/>

我更喜欢这种语法:

<path
  title="United States"
  [ngClass]="array.includes(path.title) ? 'been' : 'not-been'"
  #path
/>


感谢您的回复,但它仍然不起作用。它不会抛出任何错误,但找不到标题。它在我的测试应用程序中确实有效。你能提供一个stackblitz吗?谢谢你的回复,但它仍然不起作用。它不会抛出任何错误,但找不到标题。它在我的测试应用程序中确实有效。你能提供闪电战吗?