0

Je structure de répertoire comme:erreur XHR 404 lors de l'importation module de noeud - angulaire 2

dir 
    |--app.component.ts 

    node_modules 
    |--angular2-bootstrap-switch 

Je suis https://www.npmjs.com/package/angular2-bootstrap-switch ajouter interrupteur angular2-boostrap et selon les instructions, je devais faire, mais ain' t sûr comment.

index.html:

<script src="node_modules/es6-shim/es6-shim.min.js"></script> 
<script src="node_modules/systemjs/dist/system-polyfills.js"></script> 

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script> 
<script src="node_modules/systemjs/dist/system.src.js"></script> 
<script src="node_modules/rxjs/bundles/Rx.js"></script> 
<script src="node_modules/angular2/bundles/angular2.dev.js"></script> 


<!-- 2. Configure SystemJS --> 
<script> 
    System.config({ 
    packages: {   
     app: { 
     format: 'register', 
     defaultExtension: 'js' 
     } 

    } 
    }); 


    System.import('app/boot') 
      .then(null, console.error.bind(console)); 
    </script> 

    </head> 

    <!-- 3. Display the application --> 
    <body> 
    <my-app>Loading...</my-app> 
    </body> 

boot.ts intérieur

import {bootstrap} from 'angular2/platform/browser' 
import {AppComponent} from './app.component' 

bootstrap(AppComponent); 

DANS tsconfig.json

"exclude": [ 
    "node_modules", 
    "typings/main", 
    "typings/main.d.ts" 
    ] 

Maintenant, je dois importer ../node_modules/angular2_bootstrap_switch/components à l'intérieur de app.component.ts, comme:

import {SwitchComponent} from angular2_bootstrap_switch/components 

Je ne sais pas comment. S'il vous plaît aider.

Répondre

1

L'utilisation de ceci est très simple.

  1. Installez le node_module

    npm i angular2-bootstrap-switch 
    
  2. Dans votre système Js ajoutez la configuration que,

    'angular2-bootstrap-switch':'npm:angular2-bootstrap-switch/lib/switch.component.js' 
    
  3. Dans votre App Module importer le composant du commutateur comme

    import {SwitchComponent} from 'angular2-bootstrap-switch' 
    
  4. Ajoutez aux déclarations comme ci-dessous,

    declarations: [ SwitchComponent ], 
    
  5. utiliser dans votre code HTML comme

    <switch [status]="value" [onText]="onText" [offText]="offText" 
         [onColor]="onColor" [offColor]="offColor" [size]="size"> 
    </switch> 
    

LIVE DEMO

+0

HI, merci pour vos efforts. Je suis confronté à un problème ici. Premièrement j'ai fait npm installer angular2-bootstrap-switch et fait la plupart des étapes. J'ai eu XHR 404 pendant le chargement de l'interrupteur. Plus tard, j'ai désinstallé angular2-bootstrap-switch et puis npm je angular2-bootstrap-switch et maintenant je ne peux pas trouver le module angular2-bootstrap-switch. Je ne suis pas sûr de ce qui est si poisson, S'il vous plaît clarifier. – Gayathri

+0

êtes-vous disponible dans teamviewer? – Aravind

+0

Oui j'ai mais c'est pour une startup. Est-ce bien? – Gayathri