我想在AngularJS中做一個可摺疊的指令。我有一個風格問題。當我在AngularJS指令中使用它時,Twitter Bootstrap樣式不起作用。爲什麼Bootstrap風格不適用於AngularJS模板?
因此,這裏是我的指令代碼:
app.directive("collapsible", function() {
return {
restrict: "E",
transclude: true,
scope: {
title: '@'
},
template: '<div class="panel panel-default">' +
'<div class="panel-heading">' +
'<h3 class="panel-title" ng-click="triggerCollapsible()">{{title}}</h3>' +
'</div>' +
'<div class="panel-body" ng-show="isVisible" ng-transclude></div>' +
'</div>',
link: function (scope) {
scope.isVisible = true;
scope.triggerCollapsible = function() {
scope.isVisible = !scope.isVisible;
}
}
}
});
這是代碼的index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
</head>
<body>
<div ng-app="angularBlackbox">
<div style="margin: 15px">
<form>
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" ng-model="model.title">
</div>
<div class="form-group">
<label>Content</label>
<input type="text" class="form-control" ng-model="model.content">
</div>
</form>
<collapsible title="{{model.title}}">
<strong>Content:</strong> {{model.content}}
</collapsible>
</div>
</div>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
H3與類面板標題無法正常工作。怎麼了?
引導-theme.min.css
/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
* Copyright 2011-2016 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
bootstrap.min.css
/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
* Copyright 2011-2016 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*//*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
您是否檢查過該標題是否有任何CSS優先?你有沒有檢查''.panel-title'類是否存在於你的引導CSS? – ProEvilz
請添加您的CSS。 –
@Aleksey你爲什麼期待標題大膽? –