...例如...
<div class="month" *ngFor="#item of myCollection; #i = index">
...
</div>
Run Code Online (Sandbox Code Playgroud)
有可能做......
<div class="month" *ngFor="#item of 10; #i = index">
...
</div>
Run Code Online (Sandbox Code Playgroud)
...没有诉诸非优雅的解决方案,如:
<div class="month" *ngFor="#item of ['dummy','dummy','dummy','dummy','dummy',
'dummy','dummy','dummy']; #i = index">
...
</div>
Run Code Online (Sandbox Code Playgroud)
?
在我的蜿蜒环绕世界各地的interweb,现在特别是angular.io风格的文档,我发现许多引用@HostBinding和@HostListener.看起来它们非常基础,但不幸的是,目前它们的文档有点粗略.
任何人都可以解释它们是什么,它们如何工作并举例说明它们的用法?
我不知道如何向我的组件添加<component></component>动态类属性,但在模板html(component.html)中.
我找到的唯一解决方案是通过"ElementRef"原生元素修改项目.做一些非常简单的事情似乎有点复杂.
另一个问题是必须在组件范围之外定义CSS,从而破坏组件封装.
有更简单的解决方案吗?像<root [class]="..."> .... </ root>模板里面的东西.
角2提供@ViewChild,@ViewChildren,@ContentChild和@ContentChildren用于查询一个组件的派生元素装饰器.前两个和后两个有什么区别?
我是Angular 2的新手.我已将我的单页应用程序存储在名为"myapp"的文件夹中的服务器中.我已将基础中的网址更改为http://example.com/myapp/ `.
我的项目有两页.所以我实现了Angular 2路由.我将默认页面设置为登录.当我http://example.com/myapp/在浏览器中输入时,它会自动重定向到http://example.com/myapp/login.但如果刷新该页面我会收到404错误,说http://example.com/myapp/login找不到.
但如果我使用lite服务器运行我的项目,一切正常.在这种情况下,index.html中的URL将是"/".如何解决?
使用 Angular 8,在构建应用程序时,我们遇到以下错误:
app/modules/admin-module/pages/editor/editor.component.ts:6:27 - error TS2306:
File ...node_modules/@angular/material/index.d.ts' is not a module.
Run Code Online (Sandbox Code Playgroud) 第一次使用 firestore 时出现此错误。根据我的研究,这似乎是 Ivy 的问题。我没有很多修改 tsconfig.app.json 的经验,这是我被指出的方向,遵循其他答案。
我能够从原始项目中修改的唯一一件事是使用 Angular Fire 6 而不是 5,这是我最初按照教程所做的。
这是 package.json:
{
"name": "language",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~9.0.1",
"@angular/cdk": "^9.0.0",
"@angular/common": "~9.0.1",
"@angular/compiler": "~9.0.1",
"@angular/core": "~9.0.1",
"@angular/fire": "^6.0.0-rc.1",
"@angular/flex-layout": "^9.0.0-beta.29",
"@angular/forms": "~9.0.1",
"@angular/material": "^9.0.0",
"@angular/platform-browser": "~9.0.1",
"@angular/platform-browser-dynamic": "~9.0.1",
"@angular/router": "~9.0.1",
"firebase": "^7.8.2",
"rxjs": "~6.5.4",
"rxjs-compat": "^6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": …Run Code Online (Sandbox Code Playgroud) 我是Angular2的新手,我有一点问题:
在我的Login-Component-HTML中,我有两个复选框,我希望以双向数据绑定方式绑定到Login-Component-TypeScript.
这是HTML:
<div class="checkbox">
<label>
<input #saveUsername [(ngModel)]="saveUsername.selected" type="checkbox" data-toggle="toggle">Save username
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
这是Component.ts:
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Variables } from '../../services/variables';
@Component({
selector: 'login',
moduleId: module.id,
templateUrl: 'login.component.html',
styleUrls: ['login.component.css']
})
export class LoginComponent implements OnInit {
private saveUsername: boolean = true;
private autoLogin: boolean = true;
constructor(private router: Router, private variables: Variables) { }
ngOnInit() {
this.loginValid = false;
// Get user name from local storage …Run Code Online (Sandbox Code Playgroud) 我试图围绕着可观察者.我喜欢observables解决开发和可读性问题的方式.在我读到的时候,好处是巨大的.
关于HTTP和集合的可观察量似乎是直截了当的.我怎样才能将这样的东西转换为可观察的模式.
这是来自我的服务组件,用于提供身份验证.我希望它能像Angular2中的其他HTTP服务一样工作 - 支持数据,错误和完成处理程序.
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function(firebaseUser) {
// do something to update your UI component
// pass user object to UI component
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
Run Code Online (Sandbox Code Playgroud)
这里的任何帮助将不胜感激.我唯一的替代解决方案是创建EventEmitters.但我想这是在服务部门做事的一种可怕方式
我正在使用angualr4和angular-cli,我可以使用以下命令创建新组件.
E:\HiddenWords>ng generate component plainsight
Run Code Online (Sandbox Code Playgroud)
但我需要在平原内生成一个子组件.有没有办法处理angular-cli?
angular ×10
typescript ×2
angular-cli ×1
angularfire ×1
checkbox ×1
data-binding ×1
firebase ×1
html ×1
rxjs ×1