Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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
Angularjs ng重复未初始化_Angularjs_Angularjs Ng Repeat - Fatal编程技术网

Angularjs ng重复未初始化

Angularjs ng重复未初始化,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,正如标题所示,我似乎无法让ng repeat发挥作用,即使是精简版,有人能看看吗 还有html <!DOCTYPE html> <html ng-app="myApp"> <head> <script src="https://code.angularjs.org/1.3.0-rc.1/angular.js" data-semver="1.3.0-rc.1" data-require="angular.js@*"></script&g

正如标题所示,我似乎无法让ng repeat发挥作用,即使是精简版,有人能看看吗

还有html

<!DOCTYPE html>
<html ng-app="myApp">

<head>
  <script src="https://code.angularjs.org/1.3.0-rc.1/angular.js" data-semver="1.3.0-rc.1" data-require="angular.js@*"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>

<body ng-controller="GemsCtrl">
{{thisIsFine}}
  <table class="table table-striped">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
        <th>view</th>
        <th>Settings</th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="gem in gems">
        <th>{{gem.name}}</th>
        <th>{{gem.description}}</th>
        <th>
          <a class="btn" href="">view </a>
        </th>
        <th>Settings</th>
      </tr>
    </tbody>
  </table>
  <h1>Hello Plunker!</h1>
</body>

</html>

{{thisIsFine}}
名称
描述
看法
设置
{{gem.name}
{{gem.description}}
设置
你好,普朗克!

请告诉我哪里出了问题?

您没有将宝石正确连接到示波器

var gems = [
应该是

$scope.gems = [
您不需要以两种不同的形式声明它,这也可能会在以后引起混淆。i、 e.如果操纵
var gems
范围对象不会更新,因此中继器不会更新

如果您必须以两种不同的形式声明它,那么将$scope声明移到var声明之后。

您可以使用这种方式

var app = new angular.module('app', []).controller('GemsCtrl', function GemsCtrl($scope) {

    $scope.gems = [];
    $scope.thisIsFine = "what gives?";

    var gems = [
        {
            name: 'Azurite',
            description: "Some gems have hidden qualities beyond their luster, beyond their shine... Azurite is one of those gems.",
            shine: 8,
            price: 110.50,
            rarity: 7,
            color: '#CCC',
            faces: 14,
            images: [
                "images/gem-02.gif",
                "images/gem-05.gif",
                "images/gem-09.gif"
            ],
            reviews: [{
                stars: 5,
                body: "I love this gem!",
                author: "joe@example.org",
                createdOn: 1397490980837
            }, {
                stars: 1,
                body: "This gem sucks.",
                author: "tim@example.org",
                createdOn: 1397490980837
            }]
        },
        {
            name: 'Bloodstone',
            description: "Origin of the Bloodstone is unknown, hence its low value. It has a very high shine and 12 sides, however.",
            shine: 9,
            price: 22.90,
            rarity: 6,
            color: '#EEE',
            faces: 12,
            images: [
                "images/gem-01.gif",
                "images/gem-03.gif",
                "images/gem-04.gif"
            ],
            reviews: [{
                stars: 3,
                body: "I think this gem was just OK, could honestly use more shine, IMO.",
                author: "JimmyDean@example.org",
                createdOn: 1397490980837
            }, {
                stars: 4,
                body: "Any gem with 12 faces is for me!",
                author: "gemsRock@example.org",
                createdOn: 1397490980837
            }]
        },
        {
            name: 'Zircon',
            description: "Zircon is our most coveted and sought after gem. You will pay much to be the proud owner of this gorgeous and high shine gem.",
            shine: 70,
            price: 1100,
            rarity: 2,
            color: '#000',
            faces: 6,
            images: [
                "images/gem-06.gif",
                "images/gem-07.gif",
                "images/gem-09.gif"
            ],
            reviews: [{
                stars: 1,
                body: "This gem is WAY too expensive for its rarity value.",
                author: "turtleguyy@example.org",
                createdOn: 1397490980837
            }, {
                stars: 1,
                body: "BBW: High Shine != High Quality.",
                author: "LouisW407@example.org",
                createdOn: 1397490980837
            }, {
                stars: 1,
                body: "Don't waste your rubles!",
                author: "nat@example.org",
                createdOn: 1397490980837
            }]
        }
    ];
    $scope.gems = gems;
});
您不应该使用var gems=[

这样,当控制器执行时,对象就不能放入数组中


另一种方法是将var gems对象逐个推入$scope.gems=[]中

Move
$scope.gems=gems;
var gem=[…]之后
var app = new angular.module('app', []).controller('GemsCtrl', function GemsCtrl($scope) {

    $scope.gems = [];
    $scope.thisIsFine = "what gives?";

    var gems = [
        {
            name: 'Azurite',
            description: "Some gems have hidden qualities beyond their luster, beyond their shine... Azurite is one of those gems.",
            shine: 8,
            price: 110.50,
            rarity: 7,
            color: '#CCC',
            faces: 14,
            images: [
                "images/gem-02.gif",
                "images/gem-05.gif",
                "images/gem-09.gif"
            ],
            reviews: [{
                stars: 5,
                body: "I love this gem!",
                author: "joe@example.org",
                createdOn: 1397490980837
            }, {
                stars: 1,
                body: "This gem sucks.",
                author: "tim@example.org",
                createdOn: 1397490980837
            }]
        },
        {
            name: 'Bloodstone',
            description: "Origin of the Bloodstone is unknown, hence its low value. It has a very high shine and 12 sides, however.",
            shine: 9,
            price: 22.90,
            rarity: 6,
            color: '#EEE',
            faces: 12,
            images: [
                "images/gem-01.gif",
                "images/gem-03.gif",
                "images/gem-04.gif"
            ],
            reviews: [{
                stars: 3,
                body: "I think this gem was just OK, could honestly use more shine, IMO.",
                author: "JimmyDean@example.org",
                createdOn: 1397490980837
            }, {
                stars: 4,
                body: "Any gem with 12 faces is for me!",
                author: "gemsRock@example.org",
                createdOn: 1397490980837
            }]
        },
        {
            name: 'Zircon',
            description: "Zircon is our most coveted and sought after gem. You will pay much to be the proud owner of this gorgeous and high shine gem.",
            shine: 70,
            price: 1100,
            rarity: 2,
            color: '#000',
            faces: 6,
            images: [
                "images/gem-06.gif",
                "images/gem-07.gif",
                "images/gem-09.gif"
            ],
            reviews: [{
                stars: 1,
                body: "This gem is WAY too expensive for its rarity value.",
                author: "turtleguyy@example.org",
                createdOn: 1397490980837
            }, {
                stars: 1,
                body: "BBW: High Shine != High Quality.",
                author: "LouisW407@example.org",
                createdOn: 1397490980837
            }, {
                stars: 1,
                body: "Don't waste your rubles!",
                author: "nat@example.org",
                createdOn: 1397490980837
            }]
        }
    ];
    $scope.gems = gems;
});