首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角5noty和AOT

角5noty和AOT
EN

Stack Overflow用户
提问于 2018-04-12 12:13:03
回答 1查看 533关注 0票数 0

我使用的是角为5.2.9的noty (https://ned.im/noty),这样:

代码语言:javascript
复制
import { Injectable } from '@angular/core';
import Noty = require('noty');

@Injectable()
export class NotificationService {
    private noty(options) {
        return new Noty(options).show();
    }
    ...
}

而且效果很好。

但是,当我使用AOT (npm run build:aot)构建时,我得到:

代码语言:javascript
复制
ERROR in src/app/sys/util/notification.service.ts(2,1): error TS1202:  
Import assignment cannot be used when targeting ECMAScript modules.  
Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

这是一个基于https://github.com/gdi2290/angular-starter的项目。

当使用import Noty from 'noty';时,AOT构建是可以的,但是当运行npm run server时,我得到了ERROR TypeError: noty_1.default is not a constructor

节点_模块/noty/index.d.ts开头为:

代码语言:javascript
复制
declare module 'noty' {
    export = Noty;
}

declare class Noty {
    constructor(options?: Noty.Options);
...

我该怎么解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-12 13:16:47

我发现它是这样运作的:

代码语言:javascript
复制
/// <reference path="../../../../node_modules/noty/index.d.ts" />

import { Injectable } from '@angular/core';
import Noty = require('noty');

@Injectable()
export class NotificationService {
    private noty(options) {
        return new Noty(options).show();
    }
    ...
}

因为noty没有将d.ts放在node_ does /@type/.那我想我得手动引用了。

PS:还在tsling.json中设置tsling.json规则,否则将将引用标记为错误

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49796224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档