markdown Angular - 如何调用外部Javascript?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Angular - 如何调用外部Javascript?相关的知识,希望对你有一定的参考价值。

# Angular - How To Call External Javascript?

[SOURCE](https://stackoverflow.com/a/47348534/1602807)

## IMPORTANT:
This method of having a definition script.d.ts doesn't work on Samsung Internet Browser up to version 7.4.00.70 and some Safari on older iOS.

**Step 1.** Create `demo.js` file in `assets/javascript` folder.

```javascript
export function test1(){
    console.log('Calling test 1 function');
}
```

**Step 2.** Create `demo.d.ts` file in `assets/javascript` folder.

```typescript
export declare function test1();
```

**Step 3.** Use it in your component

```typescript
import { test1 } from '../assets/javascript/demo'; 
 @Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor() {
    console.log(test1());
  }
}
```

*Note: `js` and `.d.ts` file name should be same*

以上是关于markdown Angular - 如何调用外部Javascript?的主要内容,如果未能解决你的问题,请参考以下文章

Angular - 在 ngInclude 中调用时 ngModel 不更新

如何在angular项目中使用Editor.md

如何在angular项目中使用Editor.md

markdown 在Cloud9上运行Angular 2和Angular 4

markdown 快捷方式Angular

markdown Angular:ReactiveForm - 使用数组