2016-09-26 8 views
2

Ich habe vor kurzem angefangen an einem Angular 2 mit Bootstrap Projekt zu arbeiten. Ich möchte das Kontrollkästchen Bootstrap-Toggle zur UI hinzufügen. Ich heruntergeladen und folgte der Anweisung auf this Website. Das Kontrollkästchen wird nicht als umgeschaltet angezeigt, es wird jedoch als normales Kontrollkästchen angezeigt. Die Index.html ist:Bootstrap Toggle Checkbox funktioniert nicht mit Angular 2 Komponenten

<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"> 
 

 
    <!--[if lt IE 9]> 
 
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
 
     <![endif]--> 
 
    <script> 
 
    document.write('<base href="' + document.location + '" />'); 
 
    </script> 
 

 
    <script src="node_modules/jquery/dist/jquery.js"></script> 
 

 
    <!-- Bootstrap JS dependencies--> 
 
    <link rel="stylesheet" href="content/css/bootstrap.min.css" /> 
 
    <link rel="stylesheet" href="content/css/font-awesome.min.css"> 
 
    <link rel="stylesheet" href="content/css/bootstrap-toggle.min.css" /> 
 
    <link rel="stylesheet" href="content/css/app-styles.css" /> 
 
    <script src="content/js/bootstrap.min.js"></script> 
 

 

 
    <!-- 1. Load libraries --> 
 
    <!-- Polyfill(s) for older browsers --> 
 
    <script src="node_modules/core-js/client/shim.min.js"></script> 
 
    <script src="node_modules/zone.js/dist/zone.js"></script> 
 
    <script src="node_modules/reflect-metadata/Reflect.js"></script> 
 
    <script src="node_modules/systemjs/dist/system.src.js"></script> 
 

 
    <!-- 2. Configure SystemJS --> 
 
    <script src="systemjs.config.js"></script> 
 

 

 
    <script> 
 
    System.import('app').catch(
 
     function(err) { 
 
     console.error(err); 
 
     }); 
 

 
    $(function() { 
 
     $('#showOpen').bootstrapToggle(); 
 
    }) 
 
    </script> 
 

 
</head> 
 

 
<body> 
 

 
    <my-web-app>Loading ...</my-web-app> 
 

 
    <script src="content/js/bootstrap-toggle.js"></script> 
 

 
</body> 
 

 

 
</html>

Code-Schnipsel

Hier my-web-app ruft eine Angular 2-Komponenten, die eine Form erzeugt. Das Formular hat Checkbox als

<div class="form-group"> 
 
    <label for="showOpen" class="col-md-4 control-label">Show Open :</label> 
 
    <div class="col-md-1 checkbox"> 
 
    <input [(ngModel)]="model.showOpen" name="showOpen" type="checkbox" id="showOpen" data-toggle="toggle" checked class="control-form"> 
 
    </div> 
 
</div>

Dies ist nicht Checkbox als Toggle Checkbox zeigt. Das Kontrollkästchen wird als normales HTML-Kontrollkästchen angezeigt.

Wie Sie sehen können, habe ich auch den Initialisierungscode in index.html hinzugefügt.

Aber wenn ich Kontrollkästchen als erstes Element (vor My-Web-App) in der Index.html-Datei hinzufügen, wird es korrekt angezeigt. Nicht sicher, was ich vermisse. Kannst du bitte helfen.

Antwort