【问题标题】:Angular 6 /Javascript - Calling two methods in (nglick). Component and JsAngular 6 /Javascript - 在 (nglick) 中调用两种方法。组件和 Js
【发布时间】:2019-05-15 19:11:12
【问题描述】:

我试图在我的click 事件中进行两次调用,其中一次调用用于我的组件,另一次用于我的javascript 函数。下面是我的代码:

事件点击角度:

<button type="button" class="btn btn-primary" (click)="Plans(); " [attr.aria-expanded]="!isCollapsed"
aria-controls="collapseBasic">Test</button>

我的组件.ts:

Plans(){
      this.limparCombinadoList();
      this.codCombinadoPadrao = "dgc" + this.value.toString();
      this.service.combinadoTipoRisco(this.codCombinadoPadrao)
      .subscribe(
                result  => {
                this.coberturas = result.data;
                this.premioFinalCobertura = result.premioFinalCombinado
                this.processarDados(this.coberturas,this.premioFinalCobertura)
            });
    }

我的 Javascript 函数:

<script type="text/javascript">
  function renderDiv(){
    $.BrunoLeite.init('[data-animation]');
  }
</script> 

我的 javascript 文件

hs.onscroll-animation.js

(function($) {
  'use strict';

   $.BrunoLeite = {

    /**
     * Base configuration.
     *
     * @var Object _baseConfig
     */
    _baseConfig: {
      bounds: -100,
      debounce: 50,
...

}}

【问题讨论】:

  • alerta2 是否有任何理由不在角度范围内?
  • @briosheje 是 javascript 中的一个示例调用
  • 是的。我用我需要的东西更新了帖子。感谢您的支持。
  • 您知道angular 有一个动画模块,是吗? angular.io/guide/animations
  • @theheadrush,是的。我正在导入我在 hml5 / bootstrap 中的模板,在单击事件之后,我执行服务调用并使用新数据呈现子组件

标签: javascript angular html angular6 angular7


【解决方案1】:

你可以调用两个用;分隔的,像这样:

<button type="button" class="btn btn-primary" (click)="Plans(); alerta2();" [attr.aria-expanded]="!isCollapsed"
aria-controls="collapseBasic">Test</button>

此外,您必须将您的函数 alerta 移动到您的 component.ts 文件中,更改:

function alerta2() {
    alert("Bruno Leite")
}

到:

alerta2() {
    console.log("Bruno Leite")
}

【讨论】:

  • 如何将 Javascript 放入 .ts 文件中?
  • function alerta2() {alert("Bruno Leite") }更改为alerta2() {console.log("Bruno Leite") }
  • 对不起,我放了一个javascript调用的例子,但我需要的不是警报函数,而是调用另一个文件中的函数。对该函数的调用是: $ .BrunoLeite.init ('[数据动画]');我会更新我的帖子
【解决方案2】:

alerta2 函数移动到组件内,并从(click) 事件中调用它。

 alerta2(){
   alert("Bruno Leite")
 }


(click)="Plans();alerta2();"

【讨论】:

    猜你喜欢
    • 2019-06-23
    • 2014-09-13
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多