我试图将元素的高度设置为其宽度。它应该根据网络浏览器分辨率的变化自动缩放/保持大小比例。有没有办法只用 html 模板来做到这一点?就像是:
<div class="tile" #square [ngStyle]="{'height.px': square.width}">
Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的错误,我无法找出原因.根据:来自路由的id,我正在获取表privateLessons,然后搜索具有正确id的一个对象并显示到我的模板中.最后,我得到了我想要的效果,数据显示正确,但我在控制台中得到两个相同的错误:
ERROR TypeError: Cannot read property 'id' of undefined
at Object.eval [as updateRenderer] (DetailedAnnouncementComponent.html:3)
at Object.debugUpdateRenderer [as updateRenderer] (core.es5.js:13094)
at checkAndUpdateView (core.es5.js:12241)
at callViewAction (core.es5.js:12601)
at execComponentViewsAction (core.es5.js:12533)
at checkAndUpdateView (core.es5.js:12242)
at callViewAction (core.es5.js:12601)
at execEmbeddedViewsAction (core.es5.js:12559)
at checkAndUpdateView (core.es5.js:12237)
at callViewAction (core.es5.js:12601)
Run Code Online (Sandbox Code Playgroud)
如何解决?
详细-announcement.html
<div class="detailed-announcement">
{{ privateLesson.id }}
{{ privateLesson.subject }}
{{ privateLesson.category }}
{{ privateLesson.price }}
{{ privateLesson.level }}
{{ privateLesson.voivodeship }}
{{ privateLesson.city }}
{{ privateLesson.place }}
{{ privateLesson.description }}
{{ privateLesson.author }}
</div>
Run Code Online (Sandbox Code Playgroud)
详细-announcement.tmp
import …Run Code Online (Sandbox Code Playgroud)