收集 - 重复角度组件,发生了什么? [英] collection-repeat with angular component, what is happening?

查看:69
本文介绍了收集 - 重复角度组件,发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 collection-repeat 来显示数组中每个对象的角度分量。我将每个对象作为参数传递给角度组件但是当我尝试访问组件控制器中的对象时,我得到 undefined

I'm trying to use collection-repeat to display an angular component for each object in an array. I pass each object as parameter to an angular component but when I try to access the object in my component's controller I get undefined.

<ion-content>
   <ion-list>
     <ion-item
    collection-repeat="user in users"
    item-width="100%"
    item-height="90px">
        {{user}} //renders my user data correctly instantly
    <usser user="user"></user>
    </ion-item>
  </ion-list>
</ion-content>

我的组件

angular
    .module('app')
    .component('user', {
        templateUrl: 'components/user.html',
        scope: true,
        bindings: {
            user: '<'
        },
        controller: function() {
        console.log(self.user)  //prints undefined
        }
    })




  • 我是尝试在 $ timeout 中包装 console.log 但没有成功

  • 打印 self 在我的chrome控制台中显示 {user:undefined} ,但是如果我展开对象,我可以看到该用户包含正确的数据(仅适用于部分商品)

  • 访问 self.user 不起作用

    • I've tried wrapping the console.log in a $timeout without success
    • Printing self displays {user: undefined} in my chrome console, but if I expand the object I can see that user contains the correct data (only for the some of the items)
    • Accessing self.user doesn't work
    • 编辑:我真的不明白发生了什么..

      I can't really understand what's going on..

      controller: function() {
          console.log(self.user)  //prints undefined
          setTimeout(function() {
              console.log(self.user) // prints my data
          }, 2000)
      }
      

      我做错了什么?

      提前致谢!

      推荐答案

      失去了3个小时才弄明白这个

      Lost 3 hours to figure out this


      这是一个已知的问题,目前收集重复。一个修复
      将需要一个收集重复的重构,这将是一个太大的
      的变化。

      This is a known issue at the moment with collection repeat. A fix would require a refactor of collection repeat, which would be too big of a change the moment.

      总是检查Github上的问题,[ V ]所吸取的经验教训

      Always check the issues on Github, [V] lesson learned

      这篇关于收集 - 重复角度组件,发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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