内部javascript里面的cornerjs部分视图不工作? [英] Internal javascript inside angularjs partial view is not working?
问题描述
例如,我有部分查看日期选择器。初始化将在部分视图侧。
< script>
$(function(){
$('。date-pick')。datePicker();
});
< / script>
当通过路由器加载部分视图时,上述脚本将不会执行。如何在angularjs部分视图中执行这些内部javascript?
感谢Erik Duindam。
创建了如下所示的angularjs指令
// jQuery datepicker intialization的指令
应用程序.directive('jqueryDatepicker',function(){
return {
restrict:'A',
link:function(scope,element,attr){
$(' datePicker();
}
}
});
在部分视图html文件中,我已经使用了创建的指令
< input name =date1jquery-datepicker id =date1class =date-pick/>
现在jQuery日期选择器在部分视图中初始化。工作很棒!
Main thing here is to avoid loading of all JavaScript in index.html
Eg) I have partial view with date picker. Initialization will at the partial view side.
<script>
$(function() {
$('.date-pick').datePicker();
});
</script>
When the partial view loaded via router, the script mentioned above will not be executed. How to execute these kind of internal javascript inside angularjs partial view?
Thanks Erik Duindam.
Created angularjs directive which is shown below
// Directive for jQuery datepicker intialization
app.directive('jqueryDatepicker', function () {
return {
restrict: 'A',
link: function (scope, element, attr) {
$('.date-pick').datePicker();
}
}
});
And in partial view html file i have used created directive
<input name="date1" jquery-datepicker id="date1" class="date-pick"/>
Now the jQuery date picker is initialized in the partial view. Working great!
这篇关于内部javascript里面的cornerjs部分视图不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!