我正在尝试在<ng-view></ng-view>
中显示引导切换复选框。但是显示正常的HTML复选框而不是引导程序切换。但是,相同的复选框将显示为视图(主页)之外的引导程序切换。请在下面找到代码
Home.html中
<html ng-app='cgpaApp'>
<head>
<link rel="stylesheet" type="text/css" href="/styles/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/styles/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="/styles/error.css" />
<link rel="stylesheet" type="text/css" href="/styles/bootstrap-toggle.min.css"/>
</head>
<body>
<header>
<nav class="navbar navbar-default" ng-controller="HeaderController">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">CGPA Calculator</a>
</div>
<ul class="nav navbar-nav">
<li ng-class="{ active: isActive('/')}"><a href="#/Home">Home</a></li>
<li ng-class="{ active: isActive('/about')}"><a href="#/about">About</a></li>
</ul>
</div>
</nav>
</header>
Working Checkbox toggle:<input type="checkbox" data-toggle="toggle" data-on="Yes" data-off="No">
<main>
<ng-view></ng-view>
</main>
<script type="text/javascript" src="/scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="/scripts/bootstrap-toggle.min.js"></script>
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.js"></script>
<script src="scripts/angular-animate.js"></script>
<script src="scripts/angular-messages.js"></script>
<script src="app/app.js"></script>
<script src="app/controllers/cgpaController.js"></script>
<script src="app/controllers/headerController.js"></script>
<script src="scripts/validator.js"></script>
</body>
</html>
app.js
(function () {
var app = angular.module('cgpaApp',['ngRoute','ngAnimate','ngMessages']);
app.config(function ($routeProvider){
$routeProvider
.when('/',{
controller: 'cgpaController',
templateUrl:'/app/views/cgpacalculate.html'
})
.otherwise({ redirectTo:'/'});
});
})();
cgpacalculate.html
<div>
Not Working Checkbox toggle:<input type="checkbox" data-toggle="toggle" data-on="Yes" data-off="No" >
</div>
.....some code
Home.html 中的复选框显示为自举切换,而 cgpacalculate.html 内的复选框显示为普通复选框。
我错过了什么?
答案 0 :(得分:4)
将ID设为
复选框<div>
Not Working Checkbox toggle:<input id="toggle-one" type="checkbox" data-toggle="toggle" data-on="Yes" data-off="No" >
</div>
并在您的控制器中将其初始化为
$('#toggle-one').bootstrapToggle();
here是您工作代码的plnkr。
有关详细信息,请参阅http://www.bootstraptoggle.com/ - >Initialize by JavaScript