内部javascript里面的cornerjs部分视图不工作? [英] Internal javascript inside angularjs partial view is not working?

查看:203
本文介绍了内部javascript里面的cornerjs部分视图不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的主要原因是避免在index.html中加载所有JavaScript



例如,我有部分查看日期选择器。初始化将在部分视图侧。

 < 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆