在jQuery 1.6.1中进行了更改之后,我一直在尝试在HTML中定义属性和属性之间的区别.
查看jQuery 1.6.1发行说明(靠近底部)的列表,似乎可以按如下方式对HTML属性和属性进行分类:
属性:所有具有布尔值或UA计算的值,例如selectedIndex.
属性:可以添加到既不是布尔值也不包含UA生成值的HTML元素的"属性".
思考?
我觉得我错过了什么.当我尝试data attribute在我的中使用时template,像这样:
<ol class="viewer-nav">
<li *ngFor="#section of sections" data-value="{{ section.value }}">
{{ section.text }}
</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
Angular 2 崩溃:
EXCEPTION:模板解析错误:无法绑定到"sectionvalue",因为它不是已知的本机属性("
] data-sectionvalue ="{{section.value}}"> {{section.text}}
我显然遗漏了一些语法,请帮忙.
在ts is_edit = true中禁用...
<input [disabled]="is_edit=='false' ? true : null" id="name" type="text" [(ngModel)]="model.name" formControlName="name" class="form-control" minlength="2">
Run Code Online (Sandbox Code Playgroud)
我只是想根据true或禁用输入false.
我试过以下:
[disabled]="is_edit=='false' ? true : null"
[disabled]="is_edit=='true'"
[disabled]="is_edit"
Run Code Online (Sandbox Code Playgroud) 如果我们尝试这样的代码:
<td [colspan]="1 + 1">Column</td>
Run Code Online (Sandbox Code Playgroud)
或这个:
<td colspan="{{1 + 1}}">Column</td>
Run Code Online (Sandbox Code Playgroud)
我们很快发现" colspan不是一个已知的原生属性".
从A2文档中我们了解到:
该元素没有colspan属性.它具有"colspan"属性,但插值和属性绑定只能设置属性,而不能设置属性.
我们必须这样做:
<td [attr.colspan]="1 + 1">Column</td>
Run Code Online (Sandbox Code Playgroud)
这是公平的.
我的问题是,为什么colspan不是DOM的属性,如果它缺少,浏览器怎么可能呈现表,因为浏览器呈现DOM而不是HTML?
另外,如果我打开Chrome检查器,然后转到属性选项卡,为什么我可以将colspan视为Element的属性?
为什么DOM表现出这种不一致性?
我有一些代码在元素上使用Polymer属性,例如:
<paper-drawer-panel force-narrow>
聚合物的工作方式是我不能简单地说force-narrow="false"如果我想要禁用该属性,它必须完全删除.Angular2中是否有办法有条件地删除整个属性?我似乎无法找到有关此主题的任何信息.我可以使用ngIf和重复使用和不使用属性的整个元素,但如果可能的话我宁愿不这样做.谢谢!
我正在试验Angular2和Angular Material.我曾经*ngFor让Angular <input>为我生成元素.但是,在生成的网页中,生成的元素没有name属性.
这是代码的一部分order-form.component.html,它要求用户输入不同种类的水果的数量:
<md-list-item>
<md-icon md-list-icon>shopping_cart</md-icon>
<md-input-container *ngFor="let fruit of fruits" class="fruit-input">
<input mdInput [(ngModel)]="order[fruit]" [placeholder]="capitalize(fruit)"
[id]="fruit" name="{{fruit}}" required value="0" #fruitInput
(input)="onInput(fruitInput)">
</md-input-container>
</md-list-item>
Run Code Online (Sandbox Code Playgroud)
这是相应的order-form.component.ts:
import { Component, OnInit } from "@angular/core";
import { Order } from "app/order";
import { PAYMENTS } from "app/payments";
import { OrderService } from "app/order.service";
@Component({
selector: 'app-order-form',
templateUrl: './order-form.component.html',
styleUrls: ['./order-form.component.css']
})
export class OrderFormComponent implements OnInit {
order = new Order();
payments = …Run Code Online (Sandbox Code Playgroud) 我使用Angular 2.0框架并尝试创建一个输入组件.我也使用谷歌MDL,它的HTML结构需要输入标签.Angular给了我一个例外:
EXCEPTION: Template parse errors:
Can't bind to 'for' since it isn't a known native property ("s="mdl-textfield__input" type="text" id="{{input_id}}">
<label class="mdl-textfield__label" [ERROR ->]for="{{input_id}}">{{input_label}}</label>
</div>"): InputUsernameComponent@2:44
Run Code Online (Sandbox Code Playgroud)
这是代码:
import {Component} from 'angular2/core';
import {Input} from 'angular2/core';
@Component({
selector: 'input-username',
template: `<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="{{input_id}}">
<label class="mdl-textfield__label" for="{{input_id}}">{{input_label}}</label>
</div>`
})
export class InputUsernameComponent {
@Input('input-id') input_id: string;
@Input('input-label') input_label: string;
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我需要在本地或外部资源有条件地指向相同的锚链接.我试过了
<a [href]="outside?externalUrl:null" [routerLink]="outside?[]:['/route',id]" >test</a>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我没有收到任何错误,但它指向同一本地页面并忽略外部URL.有任何想法吗?
另一个选择是构建链接,但我找不到任何文档如何访问routerLink服务内部
编辑:我知道我可以克隆整个链接,*ngIf但我不想这样做,我的链接包含一个带有大量选项的视频标签
我想创建一个具有不需要值的属性的组件.例如,而不是像这样的东西:(我现在有)
<app-document [mode]="'edit'" ... ></app-document>
Run Code Online (Sandbox Code Playgroud)
要么
<app-document [editMode]="true" ... ></app-document>
Run Code Online (Sandbox Code Playgroud)
我宁愿:
<app-document editMode ...></app-document>
Run Code Online (Sandbox Code Playgroud)
因此组件本身必须查看属性editMode是否存在.当我有很多这样的属性时,这看起来会更清晰.我还没有看到有关如何执行此操作的任何文档.它可行吗?
如果满足条件,我disabled该如何添加input?
我今天拥有的:
<input class="previous" [attr.disabled] = "active === 1 ? 'disabled' : ''">
但这增加了disabled="disabled",我只想要disabled.
所以我需要的是:<input class="previous" disabled>如果满足条件.
angular ×9
dom ×2
html ×2
javascript ×2
attributes ×1
input ×1
ngfor ×1
polymer-1.0 ×1
properties ×1
typescript ×1