2015-01-05 27 views
-1

HTML:上添加刪除HTML標籤鏈接NG-IF函數

<a data-ng-if="price" data-ng-click="selected(price)"> 
    <div> 
     ... 
    </div> 
</a> 

我想刪除<a></a>如果data-ng-if="!price"

有誰知道這樣做的正確方法是什麼?

+1

你想通過刪除錨元素是什麼行爲?你只是想不要點擊。 –

+0

我還不確定你想要什麼。你可以請嘗試解釋它。 –

+0

@ShashankAgrawal是的,我希望不要點擊 – Mercer

回答

1

有兩種選擇,第一種是內在的內容移動到一個腳本,並在兩個地使其:

<script type="text/ng-template" id="main-content.html"> 
     <div>...your inner content</div> 
</script> 

<a ng-if="price" data-ng-click="selected(price)"> 
    <div ng-include="'main-content.html'"></div> 
</a> 

<div ng-if="!price" ng-include="'main-content.html'"></div> 

第二種方法是,你可以使用CSS來使其不點擊:

<a ng-class="{no-price: !price}" data-ng-click="selected(price)"> 
    <div> 
     ... 
    </div> 
</a> 

而在你的CSS:

a.no-price, a.no-price:hover, a.no-price:visited, a.no-price:focus { 
    color: black; // normal color 
    pointer-events: none; // no clickable 
    text-decoration: none; // No link feel 
}