简体   繁体   English

为什么没有显示元素列表?

[英]Why isn't list of elements showing up?

I am working on an AngularJS tutorial 我正在研究AngularJS 教程

This tutorial covers the ng-repeat directive, an AngularJS directive used repeating data. 本教程介绍了ng-repeat指令,这是一个用于重复数据的AngularJS指令。

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) 为了显示ng-repeat的示例,作者以JSON格式输入元素周期表元素,并将元素名称,元素#等覆盖到控制器逻辑中($ scope)

To display the elements(code below), the author simply used the directive with a html un-ordered list 为了显示元素(下面的代码),作者只使用了带有html无序列表的指令

<ul>
  <li data-ng-repeat="element in periodic.elements">{{element.name}} </li>
</ul>

I tried doing the same JsFiddle but the list of elements isn't showing up, only {{element.name}} 我尝试做同样的JsFiddle,但是没有显示元素列表,只有{{element.name}}

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. 起初我以为这是AngularJS语法问题,但我检查了scope属性,控制器名称是否匹配等。...我确保还要在JsFiddle中启用AngularJS选项。

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
            }
        ]
       };
    });

Working Fiddle 工作小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM