Template parse errors: Can't bind to 'ngStyle' since it isn't a known property of 'div'. ("

2023-05-16

  • 1、背景

开发个公共组件,在组件中使用指令一直报错。

template: `
    <div class="content-text-bgp">
      <div class="content-text" *ngIf="sort" [ngStyle]="{'width': minWidth+'px'}">
        <div *ngFor="let item of sort; let i = index" 
             [ngClass]="{'content-text-title' : true,
              'content-text-title-sort': i > 0}">
          <div style="float: left">{{item.title}}</div>
          <div style="float: left; margin-left: 2em;">
            <span><img src="assets/img/smallCard/{{item.sort}}.png" class="sort-content-up"></span>
            <span style="padding-left: 0.5em">{{item.value}}</span>
          </div>
        </div>
      </div>
      <div class="content-text" *ngIf="!sort" [ngStyle]="{'width': minWidth+'px'}">
        <div class="content-text-title">{{title}}</div>
        <div class="content-text-content">{{this.util.toThousands(value, null)}}</div>
      </div>
    </div>
  `,
  • 2、问题原因

angular的指令模块BrowserModule CommonModule 未导入。

  • 3、解决办法

在app.module.ts中导入BrowserModule 

import {BrowserModule} from '@angular/platform-browser';
@NgModule({
    declarations: [
        
    ],
    imports: [
        BrowserModule,
        
    ],
    providers: [
        
    ],
    bootstrap: [AppComponent]
})

在你需要使用的模块中导入CommonModule

import { NgModule } from '@angular/core';
import { D3WidgetComponent } from './d3.widget';
import { SamllCardComponent } from './small.card';
import { CommonModule } from '@angular/common';
export const SCHEMA_THIRDS_COMPONENTS = [
  D3WidgetComponent,
  SamllCardComponent,
];

@NgModule({
  declarations: SCHEMA_THIRDS_COMPONENTS,
  entryComponents: SCHEMA_THIRDS_COMPONENTS,
  imports: [CommonModule],
  exports: [...SCHEMA_THIRDS_COMPONENTS],
})
export class JsonSchemaModule {}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Template parse errors: Can't bind to 'ngStyle' since it isn't a known property of 'div'. (" 的相关文章

  • Spring LDAP - 绑定成功连接

    我正在尝试使用 Spring LDAP 和 Spring 安全性进行身份验证 然后查询我们的公司 LDAP 我设法使身份验证工作 但当我尝试运行搜索时 我总是遇到以下异常 为了执行此操作 必须在连接上成功完成绑定 经过大量研究后 我有一个理
  • 将列表绑定到 GridView

    我有一个信用卡对象列表 信用卡类别如下 using System using System Collections Generic using System Linq using System Web namespace Client pu
  • 使用 WPF 将 ObservableCollection.Count 绑定到标签

    我有一个简单的Label这应该包括界限 Count某财产的价值ObservableCollection 问题是 结果始终为 0 零 相同的属性绑定到 DataGrid 它可以完美地工作 甚至可以在集合中发生更改时进行更新 我在这里做错了什么
  • Java 绑定异常

    即使重用地址设置为 true 什么会导致 TCP 套接字抛出 java net BindException 地址已在使用中 仅当应用程序快速重新启动时才会发生这种情况 在 CentOS 5 Linux 操作系统上运行 这有点解释它 http
  • 将 Param 与参数数组绑定

    我有一个函数可以执行此操作 function registerUser firstName lastName address postcode email password params array firstName lastName a
  • 尽管在前台运行且使用 START_STICKY,但在终止后无法重新启动服务

    我面临着一个关键问题 即绑定服务作为前台运行并带有通知 正如我找到的大多数教程和解决方案所提到的 我所做的一切都是正确的 我有一个启动服务然后与其绑定的活动 在服务的 onCreate 中 我使用 startForeground 并显示通知
  • 未捕获的类型错误:对象 [object Object] 没有方法“on”

    谁能帮我解决这个问题 当我使用最新 或较新 版本的 jQuery 时 下面的小脚本可以正常工作 但是 当我使用旧版本的 jQuery 时 我的脚本显示on函数不存在 这是我的脚本 不适用于旧版本的 jQuery document ready
  • 如何绑定未绑定的方法而不调用它?

    在Python中 有没有一种方法可以绑定未绑定的方法而不调用它 我正在编写一个 wxPython 程序 对于某个类 我决定将所有按钮的数据分组在一起作为类级元组列表 如下所示 class MyWidget wx Window buttons
  • 使用 JSFiddle 时从 javascript 控制台调用 jQuery

    在我的调试和创建过程中 通常会从 javascript 控制台 firefox 或 chrome 内置的 firebug 触发一些 jQuery 命令 仅用于检查和测试目的 我注意到我无法使用 jQuery 调用与 JSFiddle 上页面
  • 如何将DataTemplate数据类型绑定到接口?

    我正在编写一个复合松散耦合的 MVVM WPF 应用程序 父 VM 中的子 VM 是接口而不是类实例 例如 public IChildViewModel get set 现在如何使用 DataTemplate 呈现此属性 喜欢
  • 如何在 AngularJS 指令中的元素上绑定滚动事件

    如何在 AngularJS 指令中的元素上绑定滚动事件 我在 window 上绑定滚动 但现在我需要将其更改为此类 body wrapper angular element document queryselector body wrapp
  • 在 std::function 上递归应用 std::bind 的问题

    给定一个函数f x y z 我们可以绑定x到 0 得到一个函数g y z f 0 y z 我们可以继续这样做并得到h f 0 1 2 在 C 语法中 这将是 include
  • jQuery:从另一个元素触发悬停事件

    当您将鼠标悬停在其中一个上时 div 我想要一个 a 也可以在页面的单独部分上 悬停 div class initiator div div a class Touch the div and I get hovered a div 我已经
  • jQuery.live() 无法在插件内部工作

    我正在编写一个插件 需要实时绑定点击 当我进行正常的单击绑定但不是实时绑定时 该插件工作正常 我已经将插件归结为基础知识 function fn liveBindTest function return this each function
  • React:搜索和过滤功能存在问题

    我正在开发一个组件 它应该能够 按输入搜索 使用输入字段 在触发 onBlur 事件后将调用一个函数 之后onBlur事件开始寻找 方法将运行 按所选流派过滤 用户可以从其他组件中从流派列表中选择流派 之后onClick事件启动过滤器 方法
  • 复选框绑定 CHANGE 事件

    我想在用户单击 触摸复选框后提交表单 THE HTML
  • 保持 LDAP 会话

    在 PHP 中 假设我在第 1 页有一个 LDAP 连接 ldapconn ldap connect ldapserver if ldapconn binding to ldap server ldapbind ldap bind ldap
  • 绑定地址和MySQL服务器[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我在尝试配置 MySQL 服务器时遇到了绑定地址 我为什么要配置绑定地址的详细信息在下面的链接中 多个主机名和多个权限 https sta
  • php 将变量绑定到旧 PHP 中的函数作用域

    我想将变量绑定到函数的作用域 我可以在 PHP 5 3 之后使用 use 关键字在 php 中执行此操作 但是如何在 PHP 5 3 以下的版本中执行等效操作 test use keyword function test use keywo
  • 创建可以传递参数而无需创建新组件的函数

    我的问题与这个问题有关React用于渲染函数中的绑定函数 以下不是好的做法 render div 因为每次重新渲染都会向页面添加一个新功能 最终导致浏览器内存不足 解决方案是这样做 constructor this callFunction

随机推荐