GVKun编程网logo

angularjs – 使用ng-repeat {ANGULAR.JS}加载JSON以显示数据(angularjs页面加载后再执行)

14

本文将为您提供关于angularjs–使用ng-repeat{ANGULAR.JS}加载JSON以显示数据的详细介绍,我们还将为您解释angularjs页面加载后再执行的相关知识,同时,我们还将为您提

本文将为您提供关于angularjs – 使用ng-repeat {ANGULAR.JS}加载JSON以显示数据的详细介绍,我们还将为您解释angularjs页面加载后再执行的相关知识,同时,我们还将为您提供关于AngularJS ng-repeat下使用ng-model、angularjs – Angular google maps – ng-repeat、angularjs – Angular JS ng-repeat消耗更多的浏览器内存、angularjs – Angular JS – 使用ng-repeat动态添加图标的href链接的实用信息。

本文目录一览:

angularjs – 使用ng-repeat {ANGULAR.JS}加载JSON以显示数据(angularjs页面加载后再执行)

angularjs – 使用ng-repeat {ANGULAR.JS}加载JSON以显示数据(angularjs页面加载后再执行)

我的 Html:
<divhttps://www.jb51.cc/tag/dis/" target="_blank">display" ng-controller="jsonServerBox">
    <divhttps://www.jb51.cc/tag/Box/" target="_blank">Box" ng-repeat="module in ocw.modules"> 
        <canvasdata="{{module.data}}" labels="{{module.labels}}" series="{{module.series}}"></canvas>
    </div>
</div>

我的JS:

app.controller('jsonServerBox',function($scope,$http) {
  var json = $http.get('serverBox.json').then(function(res){
          return res.data;
        });
  $scope.ocw = json;    
    });

图表没有显示,不知道为什么?我也没有在控制台中出现任何错误.

更新:我的JSON文件内容

[{"modules":[
            {
               "series":"SeriesA","data":["90","99","80","91","76","75","60","67","59","55"],"labels":["01","02","03","04","05","06","07","08","09","10"]
            },{
               "series":"SeriesB","10"]
            }

    ]}
]

控制台日志:

modules: Array[2]0: Objectdata: Array[10]0: "90"1: "99"2: "80"3: "91"4: "76"5: "75"6: "60"7: "67"8: "59"9: "55"length: 10__proto__: Array[0]labels: Array[10]0: "01"1: "02"2: "03"3: "04"4: "05"5: "06"6: "07"7: "08"8: "09"9: "10"length: 10__proto__: Array[0]series: "SeriesA"__proto__: Object1: Objectdata: Array[10]0: "90"1: "99"2: "80"3: "91"4: "76"5: "75"6: "60"7: "67"8: "59"9: "55"length: 10__proto__: Array[0]labels: Array[10]0: "01"1: "02"2: "03"3: "04"4: "05"5: "06"6: "07"7: "08"8: "09"9: "10"length: 10__proto__: Array[0]series: "SeriesB"
您的代码的问题是json是Promise对象而不是从AJAX调用返回的数据.此外,您的问题是“从AJAX请求返回”方面.确保您了解相关问题,请查看 this非常受欢迎的问题.

在Angular中使用AJAX请求设置范围数据的正确方法是在回调内部进行:

app.controller('jsonServerBox',function ($scope,$http) {
    $http.get('serverBox.json').then(function (res) {
        $scope.ocw = res.data;
    });
});

AngularJS ng-repeat下使用ng-model

AngularJS ng-repeat下使用ng-model

初学AngularJS 对于作用域的问题不是很了解,因为是自学,没有详细教程,被一个简单的问题困扰了两天。

以下是转载的内容,加深一下个人记忆。


blue:<input type="radio" value="1" ng-model="selectValue"/>
red:<input type="radio" value="2" ng-model="selectValue"/>
yellow: <input type="radio" value="3" ng-model="selectValue"/>

以上代码实现一个单选框功能,当你选中其中的一个单选框,可以从$scope.selectValue中得到你选中的的选项的value。
同时改变$scope.selectValue的值,也可以让界面上选中相应的单选框。

假设单选框的个数是不固定的,用ng-repeat来展现。

<table>
<tr ng-repeat="row in collections">
<td>
{{row.name}}: <input type="radio" value="{{row.value}}" ng-model="selectValue"/>
</td>
</tr>
</table>

当你书写了上述代码后。你会发现点击其中的对话框,$scope.selectValue中并没有保存你选中的对应单选框的值。

这是因为处在ng-repeat之间的代码,对全局的$scope里变量的内容是不可见的,像{{row.name}}里的row,并不是全局$scope里的成员。
而是为ng-repeat创建的子scope里面的。所以要引用全局$scope里的成员,你可以使用$parent 来引用全局的$scope

<table>
<tr ng-repeat="row in collections">
<td>
{{row.name}}: <input type="radio" value="{{row.value}}" ng-model="$parent.selectValue"/>
</td>
</tr>
</table>


转载地址: http://zhaoyanblog.com/archives/97.html

angularjs – Angular google maps – ng-repeat

angularjs – Angular google maps – ng-repeat

我正在尝试使用Angular Google Maps( http://angular-ui.github.io/angular-google-maps/)在循环(ng-repeat)中加载多个地图,但收到以下错误:

angular-google-maps: Could not find a valid center property

下面是代码,storeOwners是从rest API检索的,store.center是一个返回的对象,如下所示:

center: "{"latitude":-33.87787,"longitude":18.49352}"

抱歉这个fomatting

总结

以上是小编为你收集整理的angularjs – Angular google maps – ng-repeat全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

angularjs – Angular JS ng-repeat消耗更多的浏览器内存

angularjs – Angular JS ng-repeat消耗更多的浏览器内存

我有以下代码
<table>
 <thead><td>Id</td><td>Name</td><td>ratings</td></thead>
 <tbody>
   <tr ng-repeat="user in users">
    <td>{{user.id}}</td>
    <td>{{user.name}}</td>
    <td><div ng-repeat="item in items">{{item.rating}}</div></td>
   </tr>
 </tbody>
</table>

users是一个只有id和name的用户对象数组.数组中的用户对象数 – 150

items是一个只有id和rating的项目对象数组.数组中的项目对象数 – 150

当我在浏览器中渲染它时,当我在我的chrome-v23.0.1271.95中尝试分析时,它需要大约250MB的堆内存.

我正在使用AngularJS v1.0.3.

有角度的问题还是我在这里做错了什么?

这是JS小提琴

http://jsfiddle.net/JSWorld/WqSGR/5/

好吧,这不是ng-repeat本身.我认为你正在使用{{item.rating}}添加绑定.

所有这些绑定都在范围内注册,因此:

> 150 * 2 = 300(对于2个用户的信息)
> 150 * 150 = 22500(评级信息)
> 22800个手表功能共22800个dom元素.

这会将内存推到250MB的可想象值

从Databinding in angularjs起

You can’t really show more than about 2000 pieces of information to a human on a single page. Anything more than that is really bad UI,and humans can’t process this anyway.

angularjs – Angular JS – 使用ng-repeat动态添加图标的href链接

angularjs – Angular JS – 使用ng-repeat动态添加图标的href链接

我正在尝试使用angular来创建一个由主题,日期,演示者组织的不同视频的表格,并且还会被标记.

我使用ng-repeat重复我的对象数组来生成一个表.

但是,如何动态更改播放按钮的href链接?

在下面的jsfiddle中,我添加了一个静态行,每行应该是什么样子.第一列有一个链接到视频的fontawesome图标.如何编辑函数以便在ng-repeat中更新href链接?

http://jsfiddle.net/jheimpel/f139z9zx/3/

function playerCtrl($scope) {

  $scope.topics = [
   {
    "play": "play","topic": "topic 1","date": "date 1","presenter": "presenter 1","tags": "tag"
  },{
    "play": "play","topic": "topic 2","date": "date 2","presenter": "presenter 2",];

}
你可以放一个< a>在ng-repeat内部使用动态href进行标记,它的工作方式与您期望的一样 – 尽管使用ng-href更好,因此您的链接在数据绑定准备好之前不会中断.

我更新了你的小提琴:here

因此ng-repeat开头于:

<tr ng-repeat="topic in topics">
        <td><a ng-href="#/{{topic.url}}"><i></i></a></td>

(我在测试数据中添加了额外的url字段)

今天的关于angularjs – 使用ng-repeat {ANGULAR.JS}加载JSON以显示数据angularjs页面加载后再执行的分享已经结束,谢谢您的关注,如果想了解更多关于AngularJS ng-repeat下使用ng-model、angularjs – Angular google maps – ng-repeat、angularjs – Angular JS ng-repeat消耗更多的浏览器内存、angularjs – Angular JS – 使用ng-repeat动态添加图标的href链接的相关知识,请在本站进行查询。

本文标签: