gpt4 book ai didi

javascript - Bootstrap 切换复选框在 ng-view 中不起作用

转载 作者:行者123 更新时间:2023-12-01 15:56:18 25 4
gpt4 key购买 nike

我正在尝试在 <ng-view></ng-view> 中显示 Bootstrap 切换复选框.但是会显示一个普通的 HTML 复选框,而不是 Bootstrap 切换。但是,相同的复选框在 View (主页)之外显示为 Bootstrap 切换。请在下面找到代码

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 中的复选框显示为 Bootstrap 切换,而 cgpacalculate.html 中的复选框显示为普通复选框。

我错过了什么?

最佳答案

将 id 给你的复选框作为

<div>
Not Working Checkbox toggle:<input id="toggle-one" type="checkbox" data-toggle="toggle" data-on="Yes" data-off="No" >
</div>

并在您的 Controller 中将其初始化为

$('#toggle-one').bootstrapToggle();

here是您的工作代码的 plnkr。

更多信息可以引用http://www.bootstraptoggle.com/ - >Initialize by JavaScript

关于javascript - Bootstrap 切换复选框在 ng-view 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35405449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com