6px-alert-service 中文文档教程
6px Angular Alert Service
Angular 模块的开始
Getting started
这为使用 6px UI 的 Angular 4+ 应用程序提供了一个警报服务。 您需要的所有文件都在 /src 中。
注意:在 /dist
中有一个 package.json
文件是发布所需要的。
克隆回购后。 您可以从根目录运行 npm run build
。 这将运行脚本来清理、ngc、捆绑、缩小和复制。
Publish
要发布到 npm,您需要设置它,然后运行 npm run npm-to-publish
。 这使用了上面提到的包。
Local development
要在本地开发,您需要执行以下操作:
npm run build
cd dist/
npm link
这会创建一个指向全局 node_modules 的符号链接。 然后从您的工作目录:
npm link 6px-alert-service
一旦链接到模块的本地副本。 在您的 systemjs.config.js
文件中,您需要添加映射。
map: {
app: 'app',
// angular bundles
...
'6px-alert-service': 'node_modules/6px-alert-service/bundles/6px-angular-alert-service.umd.js'
}
注意:您的包的名称是在您的
rollup.config.js
文件中创建的。 Rollup us 用于创建 umd 模块。
然后将其添加到您的 app.module.ts 文件中。
import { SpxAlertServiceModule } from '6px-alert-service';
@NgModule({
imports: [
SpxAlertServiceModule
...
]
})
将标记添加到您的根 .html 文件,这将显示您的警报。
<spx-alert></spx-alert>
现在您可以通过导入服务并调用它的方法在您的应用程序中使用它。
Add an alert:
@params message: string
@params type: string['success', 'fail', 'info']
@params callback: Function
addAlert(message, type, callback);
Remove an alert:
@params index: number
removeAlertByIndex(index);
Clear all:
clearAll();
示例 -
import { SpxAlertService } from '6px-alert-service';
export class AppComponent {
constructor(private spxAlert: SpxAlertService) {}
createAlert() {
this.spxAlert.addAlert('Toast Message', 'success', this.callbackMethod);
}
callbackMethod() {
alert('Alert the callback');
}
}
Live updates locally
开发时,进行更改,然后运行 npm run build
。 完成后只需刷新即可在本地看到您的更改。
Credits
这个项目基本上是一个精简版 角异步本地存储 通过 https://github.com/cyrilletuzi。 在他的博客中,他解释了如何建立一个体面的 角度模块:https://medium.com/@ cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c0b4464#.9y88ipdk7
License
麻省理工学院
6px Angular Alert Service
A start for Angular modules
Getting started
This provides a alert service for use with Angular 4+ apps using 6px UI. All files you need live in /src.
Note: There is a package.json
file inside of the /dist
which is needed for publishing.
Once you have cloned the repo. From the root you can run npm run build
. This will run scripts to cleanup, ngc, bundle, minify, and copy.
Publish
To publish to npm you set this up, then run npm run npm-to-publish
. This uses the package noted above.
Local development
To develop locally you want to do the following:
npm run build
cd dist/
npm link
This creates a symlink to your global node_modules. Then from your working directory:
npm link 6px-alert-service
Once you are linked to your local copy of the module. In your systemjs.config.js
file you need to add you mapping.
map: {
app: 'app',
// angular bundles
...
'6px-alert-service': 'node_modules/6px-alert-service/bundles/6px-angular-alert-service.umd.js'
}
NOTE: The name of your bundle is created inside your
rollup.config.js
file. Rollup us used for creating the umd module.
Then add this to your app.module.ts file.
import { SpxAlertServiceModule } from '6px-alert-service';
@NgModule({
imports: [
SpxAlertServiceModule
...
]
})
Add the tag to your root .html file, this displays your alerts.
<spx-alert></spx-alert>
Now you can use this inside your application by importing the service and calling it's methods.
Add an alert:
@params message: string
@params type: string['success', 'fail', 'info']
@params callback: Function
addAlert(message, type, callback);
Remove an alert:
@params index: number
removeAlertByIndex(index);
Clear all:
clearAll();
Example -
import { SpxAlertService } from '6px-alert-service';
export class AppComponent {
constructor(private spxAlert: SpxAlertService) {}
createAlert() {
this.spxAlert.addAlert('Toast Message', 'success', this.callbackMethod);
}
callbackMethod() {
alert('Alert the callback');
}
}
Live updates locally
When developing, make your changes and then run npm run build
. Once this finishes just refresh and your changes should be seen locally.
Credits
This project is basically a stripped down version of angular-async-local-storage by https://github.com/cyrilletuzi. In his blog he explains how to build a decent Angular module: https://medium.com/@cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c0b4464#.9y88ipdk7
License
MIT