If a certain attribute directive
is present on an HMTL element, I would like to show some additional html content. I have searched but can't find what am looking for. For example if P tag has a directive called can-delete
, then I would like delete button to show.
<p can-delete>Hello World!</p>
This is what I got so far:
// >>> home.ts
import { Component } from "@angular/core";
import {canDelete } from "./can-delete.directive.ts";
@Component({
templateUrl:"home.html",
directives: [canDelete]
})
export class HomePage {
constructor() { }
}
// >>> home.html
<ion-header>
<ion-navbar primary>
<ion-title>
Ionic 2
</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
Content...
<p can-delete>Hello World!</p>
</ion-content>
// >>> can-delete.directive.ts
import { Directive, ElementRef } from "@angular/core";
@Directive({
selector: "[can-delete]"
})
export class canDelete {
constructor(el: ElementRef) {
//show delete button
//<button>Delete</button>
}
}