方法一
1:配置package.json添加新的依赖,然后进行update,下载新的库
"jquery":"*",
"tether":"*",
"bootstrap":"*",
"moment":"*",
"eonasdan-bootstrap-datetimepicker":"*"
2: 配置angular-cli.json
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css",
"styles.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/tether/dist/js/tether.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js",
"../node_modules/moment/min/moment.min.js",
"../node_modules/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"
],
3: 在模版中使用datatimepicker插件
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
4:在组件中对该组件进行实例化
declare var $:any;
@Component({
selector:"app-root",
templateUrl:"bootstrap.template.html"
})
export class BootstrapComponent extends OnInit{
ngOnInit(): void {
$(function () {
$('#datetimepicker1').datetimepicker();
});
}
}
方法二
- assets中添加需要的css与js
- 在index.html中添加引用
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css">
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
- 在组件中对该组件进行实例化
declare var $:any; //需要declare jquery的$
@Component({
selector:"app-root",
templateUrl:"bootstrap.template.html"
})
export class BootstrapComponent extends OnInit{
ngOnInit(): void {
$(function () {
$('#datetimepicker1').datetimepicker();
});
}
}
网友评论