角度NG-如果单独打开和关闭标签,但留下的内容 - 可选的标记 [英] angular ng-if for opening and closing tag but leave contents alone - optional tag

查看:97
本文介绍了角度NG-如果单独打开和关闭标签,但留下的内容 - 可选的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经打这几次,在这里我想有选择性地呈现一个条件标签,但留下的内容。我的使用情况是,当我有一个可选的连接指令,所以我想呈现的开始和结束&LT; A&GT; 标签,但先不谈内容在任何情况下<。 / p>

 &LT;一个NG-IF =条件&GT;&LT; P&GT;渲染我总是小于/ P&GT;&LT; / A&GT;


解决方案

做到在无角编写自定义指令的唯一方法是使用两个ngIf条件:

 &LT;一个NG-IF =条件&GT;
    &LT; P&GT;渲染我总是小于/ P&GT;
&所述; / A&GT;&LT; p NG-IF =&GT状态!;渲染我总是小于/ P&GT;

I have hit this a couple times, where I want to selectively render a tag on a condition but leave the contents. My use case is a directive when I have an optional link, so I want to render the opening and closing <a> tags but leave the contents alone in either case.

<a ng-if="condition"><p>Render me always</p></a>

解决方案

The only way to do it in Angular without writing custom directive is to use two ngIf conditions:

<a ng-if="condition">
    <p>Render me always</p>
</a>

<p ng-if="!condition">Render me always</p>

这篇关于角度NG-如果单独打开和关闭标签,但留下的内容 - 可选的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆