Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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 我的代码怎么了_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 我的代码怎么了

Javascript 我的代码怎么了,javascript,html,angularjs,Javascript,Html,Angularjs,我希望tableRow.html绘制在表格标题下,但ng repeat根本没有绘制,示例位于表格标题上方。如果我将带有示例的行直接放在index.html中的适当位置,它会画得很好。我做错了什么? index.html <html> <head> <title>Currency Exchange</title> <link rel="stylesheet" href="css/bootstrap.min.css">

我希望tableRow.html绘制在表格标题下,但ng repeat根本没有绘制,示例位于表格标题上方。如果我将带有示例的行直接放在index.html中的适当位置,它会画得很好。我做错了什么? index.html

<html>
<head>
    <title>Currency Exchange</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="css/stylesheet.css"/>
    <script type="text/javascript" src="js/angular.min.js"></script>

</head>
<body ng-app="myApp">
    <h1>A title to the table</h1>
    <div>
        <div class= "ExTableDiv">
            <table class= "ExTable">
            <thead>
                <tr>
                    <th class="column">Currency Code</th>
                    <th class="column">Currency Name</th>
                    <th class="column">Exchange Rate vs USD</th>
                </tr>
            </thead>
            <tbody ng-controller="TestController"><!--**if you try TestController as TC it will throw an error, why?**-->
                <test-directive></test-directive>
            </tbody>
            </table>
        </div>
    </div>
</body>
    <script type="text/javascript" src="js/app.js"></script>
    <script type="text/javascript" src="js/directives/tableFiller.js"></script>
</html>
tableFiller.js

(function(){
var app = angular.module('exchange-directives', []);

app.directive('testDirective', function(){
    return {
        restrict: 'E',
        templateUrl: 'js/directives/tableRow.html'
    };
});
})();
tableRow.html

<tr ng-repeat='row in TestController.table.rows'>
<td>{{row.name}}</td>
<td>{{row.rate}}</td>
<td>{{row.inverse}}</td>
</tr>
<tr>
    <td>Example 1</td>
    <td>Example 2</td>
    <td>Example 3</td>
</tr>

{{row.name}
{{row.rate}
{{row.inverse}}
例1
例2
例3
替换为


在您的控制器中,您正在设置
table=this
,因此
table.rows
实际上就是
this.rows
,因此可以通过
TestController对标记进行设置。rows
我选择回答这个问题:

另外,我在codeschool上的教程将angular.module封装在函数中,但我发现大多数其他示例都没有。有什么区别?为什么选择一个而不是另一个


这叫做or(生命)。这是一种将模块引入JavaScript的轻量级方法。这样做的目的是确保在模块顶层声明的所有变量的词法范围。如果没有类似的东西,很容易意外地引入全局变量,这通常是一个baaaad问题。

你能编辑你的问题,一次问一件事吗?你想知道为什么你的代码不起作用,还是想知道其他问题的答案?让我们先看看为什么表不起作用,问题是editedI照你说的做了但没有改变任何事情
<tr ng-repeat='row in TestController.table.rows'>
<td>{{row.name}}</td>
<td>{{row.rate}}</td>
<td>{{row.inverse}}</td>
</tr>
<tr>
    <td>Example 1</td>
    <td>Example 2</td>
    <td>Example 3</td>
</tr>