Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading Addons in Angular 2 / Typescript #792

Closed
DerekTBrown opened this issue Jul 13, 2017 · 7 comments
Closed

Loading Addons in Angular 2 / Typescript #792

DerekTBrown opened this issue Jul 13, 2017 · 7 comments
Labels
type/question A question on how to use the library

Comments

@DerekTBrown
Copy link

DerekTBrown commented Jul 13, 2017

I am not sure how to import the addons packages when using Angular 2 / Typescript. The solution I came up with is rather inelegant:

// Import Angular
	import { Component } from '@angular/core';

// Import Xterm
        import * as Terminal from 'xterm/dist/xterm';
	import style from 'xterm/dist/xterm.css';
	import 'xterm/dist/addons/fit/fit.js';

// Export Data Interface
  @Component({
    selector: 'terminal',
    template: '<div id="terminal" #terminal></div>',
    styles: [ style ]
  })

  export default class TerminalView {
		@ViewChild('terminal') container : ElementRef;
		private xterm : Terminal;

		ngOnInit(){
			this.xterm = new Terminal();
			this.xterm.open(this.container.nativeElement);
			this.xterm.fit();
		}

  }
@parisk
Copy link
Contributor

parisk commented Jul 13, 2017

@DerekTBrown feel free to continue the discussion here or posting a question in the xtermjs StackOverflow tag.

I will be closing this issue since it does not have to do with xterm.js itself, but with how you can use it in a particular context.

I am not sure what inelegant means in your case as I have no experience with Angular, but you can try using the loadAddon method which is the suggested way of consuming xterm.js.

@parisk parisk closed this as completed Jul 13, 2017
@parisk
Copy link
Contributor

parisk commented Jul 13, 2017

@DerekTBrown also, if you find a more elegant way to consume xterm.js with Angular, please let us know and we will add it in our documentation website 😄.

@parisk parisk added the type/question A question on how to use the library label Jul 13, 2017
@GavinSong123
Copy link

@DerekTBrown I want to use xterm in angular2. But the private term: Terminal; has error that Cannot find name 'Terminal'..

@DerekTBrown
Copy link
Author

@GavinSong123 did you install the typings? If not, npm install --save-dev @types/xterm

@DerekTBrown
Copy link
Author

@parisk I think the easy solution would be to export the typings from this project directly into the @types/xterm package (which is in DefinitelyTyped).

@Tyriar
Copy link
Member

Tyriar commented Jul 18, 2017

@DerekTBrown #335 is inching closer and closer to done. Once that's complete typings will be shipped with the module so it should all just work.

@GavinSong123
Copy link

@DerekTBrown Yes, I had installed xterm. And I solved it by defining private term: any. It also worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/question A question on how to use the library
Projects
None yet
Development

No branches or pull requests

4 participants