简体   繁体   English

如果字符串以E和A开头,那么我想显示与数据不同的Divs,然后从数据中删除前两个字母

[英]I want to show different Divs with data if the string starts with E and A and then delete first two letters from data

I have data coming from a API in Angular. 我有来自Angular API的数据。

 $scope.alert = alertMessage;

If the Alert message starts with E. i want to show div 1 如果警报消息以E开头,我想显示div 1

<div class= "alert 1">
<p>{{alert}}</p>
</div>

IF the Alert message starts with A i want to show div 2 如果警报消息以A开头,我想显示div 2

<div class= "alert 2">
<p>{{alert}}</p>
</div>

Also i want to trim first two characters in Alert message. 我也想修剪警报消息中的前两个字符。

Can anybody help me on this. 有人可以帮我吗?

 //If the Alert message starts with E. i want to show div 1 <div class="alert 1" ng-if="alert[0] === 'E'"><!-- show if the first character is E --> <p>{{alert.slice(2)}}</p><!-- remove the first two characters --> </div> 

ng-show toggles the appearance of the element by adding the CSS display: none style. ng-show通过添加CSS显示:无样式来切换元素的外观。 ng-if, on the other hand, actually removes the element from the DOM when the condition is false and only adds the element back once the condition turns true. 另一方面,ng-if实际上在条件为false时从DOM中删除该元素,并且仅在条件变为true时才将元素添加回去。 Just depends one what your requirements are but you could essentially use either one. 仅取决于您的需求是什么,但实际上您可以使用其中之一。

 $scope.alert = alertMessage.slice(2); 
 <div class= "alert 1" ng-show="alert.indexOf('E') == 0"><p>{{alert}}</p> </div> <div class= "alert 2" ng-show="alert.indexOf('A') == 0"> <p>{{alert}}</p> </div> 

I have used ng-if for two divs like what taplar told. 我已经将ng-if用于两个div,就像taplar所说的那样。 in case of removing 2 characters i used {{alert.substring(2)}} 在删除2个字符的情况下,我使用了{{alert.substring(2)}}

This worked . 这行得通。 Thanks Guys for your help. 谢谢大家帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有两个HTML页面。 从下一页恢复到首页时,我希望保存首页的数据状态 - there are two html pages. I want the data status of first pages to saved when I reverting from next page to first page 尝试将对象数组按降序排序到键(名称),并希望带有大写字母的数据首先出现在 vuejs - Trying to sort array of objects in descending order wrt to a key (name)and want the data with uppercase letters to show up first in vuejs 如何用不同的颜色显示文本的某些部分,即@和}之间的数据应使用不同的颜色 - How to show some part of text in different color i.e data between @ and } should be in different color 我想将Firebase数据库中的数据显示到HTML表中 - I want to show data from Firebase Database into HTML table 我想将 indexedDB 中的数据显示到视图中,我正在使用 reactjs - i want to show data from indexedDB to the view, im using reactjs 此查询有效吗? 我想更新一个表,将两个不同的表连接起来,并以两种不同的形式显示数据 - Is this query valid? I want to update a table, joining two different tables, and to display the data to two different forms 将数组中的数据插入不同的HTML Div中 - Insert data from an Array into different HTML Divs 我想显示/隐藏两个div,具体取决于从下拉列表中进行选择,但是我的脚本不起作用 - I want to show/hide two divs depending on choosing from drop down list , but my script doesn't work 从数据库中获取数据后,使用 JavaScript 将数据显示到两个不同的 div 中 - Displaying data into two different divs using JavaScript, after fetching it from db 输出是字符串,我想从数组中获取数据 - Output is string and I want to get the data from an array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM