角:NG重复不工作 [英] Angular : ng-repeat not working

查看:144
本文介绍了角:NG重复不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code,我把它从w3school。

Here is my code , i take it from w3school.

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<script type="text/javascript" src="./angular.min.js"></script>
<script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        $scope.firstName = "sparsh";
        $scope.lastName = "khandelwal";
    });
</script>
<title>Home Page</title>
</head>
<body>
    <div ng-app="myApp" ng-init="name='Sparsh'">
        <div ng-controller="myCtrl">{{firstName}}</div>
        <p>
            Name : <input type="text" ng-model="name">
        </p>
        <h1>Hello {{name}}</h1>
    </div>

    <div ng-app="" ng-init="names=['Jani','Hege','Kai']">
        <ul>
            <li ng-repeat="x in names">{{x}}</li>
        </ul>
    </div>
</body>
</html>

NG-重复第二块是行不通的。

ng-repeat in second block is not working.

下面是输出我得到浏览器

here is the output i get on browser

请帮我出

推荐答案

角只有自举的第一个发现在页面上的应用程序,即第一容器 NG-应用属性。第二个你把 NG-应用=将被忽略。虽然,你可以手动引导第二个用 angular.bootstrap 方法,在你的情况下,它更有意义来包装整个到相同的应用程序,并删除第二个 ngApp 指令:

Angular only bootstraps the first found application on the page, i.e. the first container with ng-app attribute. The second one you put, ng-app="" will be ignored. Although, you could manually bootstrap the second one with angular.bootstrap method, in your case it makes more sense to wrap entire body into the same app and remove the second ngApp directive:

<body ng-app="myApp">
    <div  ng-init="name='Sparsh'">
        <div ng-controller="myCtrl">{{firstName}}</div>
        <p>
            Name :
            <input type="text" ng-model="name" />
        </p>
        <h1>Hello {{name}}</h1>
    </div>
    <div  ng-init="names=['Jani','Hege','Kai']">
        <ul>
            <li ng-repeat="x in names">{{x}}</li>
        </ul>
    </div>
</body>

演示: http://plnkr.co/编辑/ UXTGEWOaRu82WpeOvuOz?p = preVIEW

这篇关于角:NG重复不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆