为什么不显示元素列表? [英] Why isn't list of elements showing up?
问题描述
我正在编写 AngularJS 教程
I am working on an AngularJS tutorial
本教程介绍了 ng-repeat 指令,这是一个使用重复数据的 AngularJS 指令.
This tutorial covers the ng-repeat directive, an AngularJS directive used repeating data.
为了展示 ng-repeat 的例子,作者以 JSON 格式输入元素周期表元素,包括元素名称、元素 # 等到控制器逻辑($scope)中
To show an example of ng-repeat, The author enters periodic table elements in a JSON format, covering element's name, element #, etc into controller logic($scope)
为了显示元素(下面的代码),作者简单地使用了带有 html 无序列表的指令
To display the elements(code below), the author simply used the directive with a html un-ordered list
<ul>
<li data-ng-repeat="element in periodic.elements">{{element.name}} </li>
</ul>
我尝试做同样的 JsFiddle 但元素列表没有显示,只有 {{element.name}}
I tried doing the same JsFiddle but the list of elements isn't showing up, only {{element.name}}
起初我认为这是一个 AngularJS 语法问题,但我检查了 scope 属性,如果控制器名称匹配等等......我确保在 JsFiddle 中也启用了 AngularJS 选项.
At first I thought this was an AngularJS syntax issue but I checked over the scope attribute, if the controller names match, etc.... I made sure to enable the AngularJS option in JsFiddle as well.
有谁知道问题是什么或者为什么这个列表没有出现?
Does anyone know what the issue is or why this list isn't showing up?
推荐答案
你忘记完成控制器语法 '});'在代码的末尾.
You forget completing controller sytax '});' at the end of the code.
'use strict';
var chemistryApp = angular.module('chemistryApp', []);
chemistryApp.controller(
'chemistryController',
function chemistryController($scope) {
$scope.periodic = {elements: [
{
"atomicNumber": 1,
"name": "Hydrogen",
"atomicWeight": 1.00794,
"phase": "Gas",
"ionization": 13.5984,
"melting": -259.15,
"boiling": -252.87
},
{
"atomicNumber": 2,
"name": "Helium",
"atomicWeight": 4.002602,
"phase": "Gas",
"ionization": 24.5874,
"melting": 0,
"boiling": -268.93
},
{
"atomicNumber": 3,
"name": "Lithium",
"atomicWeight": 6.941,
"phase": "Solid",
"ionization": 5.3917,
"melting": 180.54,
"boiling": 1342
}
]
};
});
工作 小提琴
这篇关于为什么不显示元素列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!