ngOnChanges在Angular4中不起作用

时间:2018-05-04 04:04:04

标签: angular typescript ngonchanges

我知道我不是第一个提出这个问题的人,而且我已经在Stackoverflow中尝试过这么多关于此问题的解决方案,但没有任何对我有帮助。

当我的父组件中有一个手风琴菜单,当用户点击这些菜单时,点击菜单的隐藏ID将传递给子组件。在子组件中,我需要根据父组件值调用API

这里我在Stackblitz中重现了我的问题,请看看并给我解决这个问题的解决方案。

https://stackblitz.com/edit/angular-bootstrap-carousel-dynamic2-dssqrc?file=app/child/child.component.ts

1 个答案:

答案 0 :(得分:1)

我没有找到触发点击事件的代码:(。模板变量在循环中但是在它之外使用。我推荐一种替代解决方案,通过<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://printjs-4de6.kxcdn.com/print.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.4/semantic.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.4/semantic.css" rel="stylesheet"/> <div id="modaldiv" class="ui modal"> <button type="ui button" id="button" onclick="printJS({ printable: 'modaldiv',type: 'html',showModal:true, printContainer: true,copyTagClasses: true})"> Print </button> //print button and printjs command active <i class="close icon"></i> <div class="header"> Profile Picture </div> <div class="content"> <div class="ui medium image"> <img src="img/bmw5.png"> </div> <div class="description"> <div class="ui header">We've auto-chosen a profile image for you.</div> <p>We've grabbed the following image from the <a href="#" target="_blank">gravatar</a> image associated with your registered e-mail address.</p> <p>Is it okay to use this photo?</p> </div> </div> <div class="actions"> <div class="ui black button"> Nope </div> <div class="ui positive right labeled icon button"> Yep, that's me <i class="checkmark icon"></i> </div> </div> </div> <a class="item ui button" id="logIn"> <i class="user icon"></i> Log In </a> // modal open login button中的属性。在stackblitz中分叉这里https://stackblitz.com/edit/angular-bootstrap-carousel-dynamic2-exbr5f?file=app%2Fapp.component.html