Giter Site home page Giter Site logo

Comments (5)

 avatar commented on May 24, 2024

changes 是一个 SimpleChanges 类型对象,changes 里面有 questionnaire 这个 SimpleChange 类型的子对象,注意"s"结尾的区别。
questionnaire 是一个对象,不是一个方法

from angular2-questionnaire.

clfeng avatar clfeng commented on May 24, 2024

老师说还没注意到有没‘s’,谢谢啦。然后后来自己也debugger了一下,现在比较明白了。然后里面的github的代码存在着这么一个bug:

  ngOnChanges(changes: SimpleChanges){
      let questionnaireChange = changes['questionnaire'];
      if( questionnaireChange.previousValue.state && 
            questionnaireChange.currentValue.state !== questionnaireChange.previousValue.state){
          this.questionnaire = changes['questionnaire'].currentValue;
          this.setState();
      }
  }

这段代码中,当第一次调用到ngOnChanges的时候questionnaireChange.previousValue为undefined,所以调用questionnaireChange.previousValue.state会报错,感觉原本的代码意图应该是

if( questionnaireChange.previousValue&& 
            questionnaireChange.currentValue.state !== questionnaireChange.previousValue.state)

还有一点想请教下。changes所拥有对象的名称是根据@input来判断的?理由是OnChanges是用来在@input的值变化时调用的钩子?不知怎么理解对不对

from angular2-questionnaire.

 avatar commented on May 24, 2024

恩,谢谢反馈问题。

from angular2-questionnaire.

 avatar commented on May 24, 2024

OnChanges的参数值是根据@input定义的,当@input() 修饰的变量发生变化就会触发 OnChanges钩子

from angular2-questionnaire.

clfeng avatar clfeng commented on May 24, 2024

想明白了。谢谢

from angular2-questionnaire.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.