如何包含特定于每个视图angularjs的javascript文件 [英] how to include javascript file specific to each view angularjs

查看:78
本文介绍了如何包含特定于每个视图angularjs的javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是loadjs文件在将其绑定到网格之前并不总是被加载。我已阅读有关使用指令的其他帖子,但我不明白如何在我的情况下使用它们。

The problem I am having is that the loadjs file doesn't always get loaded before I bind it to the grid. I have read other posts regarding using directives but I don't understand how to use them in my case.

代码应加载特定视图,每个视图依次具有在视图最终被撤销之前需要加载的特定javascript文件

The code should load a specific view each view in turn has a specific javascript file that needs to be loaded before the view is finally renered

因此视图1可能是具有datagrid.js文件依赖性的数据网格,而view2是具有listview的列表视图。 js dependancy

So view 1 might be a datagrid with datagrid.js file dependancy and view2 is a listview with listview.js dependancy

谢谢。

Function MyCtrl1($scope) {
$scope.$on('$viewContentLoaded', function() {

     //Load file if not already loaded
    isloadjscssfile("js/model/gridmodel.js", "js")


  $("#grid").kendoGrid({
                    dataSource: getdatasource(),
                    pageable: true,
                    height: 400,
                    toolbar: ["create"],
                    columns: [
                        "ProductName",
                        { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "150px" },
                        { field: "UnitsInStock", title:"Units In Stock", width: "150px" },
                        { field: "Discontinued", width: "100px" },
                        { command: ["edit", "destroy"], title: " ", width: "210px" }],
                    editable: "inline"
                });
});

}

推荐答案

你不能。 Angular不会从模板加载javascript部分。

You can't. Angular does not load javascript parts from a template.

您应该做的是将它们包含在主应用程序中。应用程序启动时应加载所有控制器。 (这是您放置 npApp 指令的地方)

What you should do is to include them in your main application anyway. All of the controllers should be loaded while the main app is initiating. (This is where you put your npApp directive)

这篇关于如何包含特定于每个视图angularjs的javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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