アンギュラー11の場合
npm install alertifyjs --save
そして、配列のangular.json
下にこれらの行を置きますstyles
"styles": [
"node_modules/alertifyjs/build/css/alertify.min.css",
"node_modules/alertifyjs/build/css/themes/bootstrap.min.css"
],
そして、配列の下のangular.json
ファイルの下にこの行を置きます。scripts
"scripts": [
"node_modules/alertifyjs/build/alertify.min.js"
]
その後、という新しいサービスを作成しますalertify.service.ts
import { Injectable } from '@angular/core';
declare let alertify: any;
@Injectable({
providedIn: 'root'
})
export class AlertifyService {
constructor() { }
confirm(message: string, okCallback: () => any) {
alertify.confirm(message, function(e:any) {
if (e) {
okCallback();
}
});
}
success(message: string) {
alertify.success(message);
}
error(message: string) {
alertify.error(message);
}
warning(message: string) {
alertify.success(message)
}
message(message: string) {
alertify.message(message)
}
}
このサービスapp.module.ts
をprovider
配列に登録します
providers: [
AlertifyService
]
このサービスをコンポーネントに挿入します。