ho visto in this post che è possibile utilizzare SystemJS per caricare i file JavaScript esterno nelle mie componenti angolare 2.Come potrei usare uno system.import() nel componente angolare 2
Nel mio index.html:
<script>
System.config({
packages: {
"frontOfficeA2/src": {
format: 'register',
defaultExtension: 'js'
},
"angular2-jwt": {
"defaultExtension": "js"
},
"ng2-bootstrap": {
"defaultExtension": "js"
},
"system": {
"defaultExtension": "js"
}
},
map: {
"angular2-jwt": "lib/angular2-jwt",
"ng2-bootstrap": "lib/ng2-bootstrap",
"moment": 'lib/moment/moment.js',
"system": 'lib/systemjs/dist/system.src.js'
}
});
System.import('frontOfficeA2/src/app.js').then(null, console.error.bind(console));
</script>
E la mia componente:
import {Component} from 'angular2/core';
import { DATEPICKER_DIRECTIVES } from 'ng2-bootstrap/ng2-bootstrap';
import { System } from 'system';
@Component({
selector: 'main',
templateUrl: 'app/components/main/main.html',
styleUrls: ['app/components/main/main.css'],
providers: [],
directives: [DATEPICKER_DIRECTIVES],
pipes: []
})
export class Main {
date: Date = new Date();
constructor() {
System.import('path/to/your/file').then(refToLoadedScript => {
refToLoadedScript.someFunction();
});
}
}
Infine, quando inizio la mia app:
frontOfficeA2/src/app/components/main/main.ts (3,24): errore TS2307: impossibile trovare il 'sistema' del modulo.
Se qualcuno ha un'idea di quello che sto facendo male .. :)
Grazie :)
Hai già caricato systemjs nel tuo index.html. Non è necessario importarlo. –