Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度JS中包含Ng的未定义函数_Javascript_Html_Angularjs_Angularjs Ng Include - Fatal编程技术网

Javascript 角度JS中包含Ng的未定义函数

Javascript 角度JS中包含Ng的未定义函数,javascript,html,angularjs,angularjs-ng-include,Javascript,Html,Angularjs,Angularjs Ng Include,我在AngularJs中遇到一个未定义函数的问题,我在互联网上没有找到任何合适的解决方案: 我尝试建立一个单页网站。index.html中嵌套了几个选项卡,其中包含ng include 如果我打开tab1.html allone,角度函数将按预期工作。 但是,如果我打开index.html(使用嵌入的tab1.html),函数是未定义的,角度函数无法正常工作 如果有人能帮助我,我将非常感激 -代码如下- index.html <!--Tab-Container--> <div

我在AngularJs中遇到一个未定义函数的问题,我在互联网上没有找到任何合适的解决方案: 我尝试建立一个单页网站。index.html中嵌套了几个选项卡,其中包含ng include

如果我打开tab1.html allone,角度函数将按预期工作。 但是,如果我打开index.html(使用嵌入的tab1.html),函数是未定义的,角度函数无法正常工作

如果有人能帮助我,我将非常感激

-代码如下-

index.html

<!--Tab-Container-->
<div lang="en" ng-app="IndexPage" ng-cloak class="tabsdemoDynamicHeight" ng-cloak="">
<md-content>
    <md-tabs md-dynamic-height="" md-border-bottom="">

        <!-- Content TAB 1 -->
          <md-tab label="Tab1">
            <md-content class="md-padding">
                <div ng-include src="'views/tab1.html'"></div>
            </md-content>
          </md-tab>           

        <!-- Content TAB 2 --> 
        ...

      </md-tabs>      
</md-content>
</div>
<script type="text/javascript">angular.module('IndexPage', ['ngMaterial']);</script>
tab1.html

<body>
<div ng-app="tableapp" ng-controller="Ctrl" >
            <a href="#" editable-text="user.name">{{ user.name || "empty" }}</a>
        </div>
</body>

你不能在
ng app
中定义
ng app
,也不能在同一
html
页面上有多个
标记,这就是angular将
tab1.html
模板插入
index.html
页面时发生的情况

如果
tab1.html
只是主
app
中的一个视图,则不能以

<body>
   <div ng-app="tableapp" ng-controller="Ctrl" >
            <a href="#" editable-text="user.name">{{ user.name || "empty" }}</a>
   </div>
</body>

但更像是:

<div>
   <div ng-controller="Ctrl" >
            <a href="#" editable-text="user.name">{{ user.name || "empty" }}</a>
   </div>
</div>


当然,将
tableapp
模块注入主
IndexPage
模块。

如果您没有告诉index.js包含tableapp模块,请尝试将其作为依赖项添加。为什么要定义
IndexPage
两次?(index.js和index.html)从index.html中删除脚本标记,并将其替换为脚本包含标记。。包括index.js…将是首先要做的事情。此外,您正在创建两个独立的模块和应用程序(即tableapp和IndexPage)。。没必要这么做。只需在主应用程序中包含选项卡模块。感谢您的快速帮助。我合并了index.js和tab1.js;我删除了冗余的IndexPage定义,但错误仍然相同。我该如何向IndexPage模块添加依赖项?非常感谢,这对我帮助很大。现在我的代码开始工作了!
<body>
   <div ng-app="tableapp" ng-controller="Ctrl" >
            <a href="#" editable-text="user.name">{{ user.name || "empty" }}</a>
   </div>
</body>
<div>
   <div ng-controller="Ctrl" >
            <a href="#" editable-text="user.name">{{ user.name || "empty" }}</a>
   </div>
</div>