我正在使用angular2进行开发,并想知道ng-disabled在angular2中是否有任何替代方案.
对于前者 下面的代码是angularJS:
<button ng-disabled="!nextLibAvailable" ng-click="showNext('library')" class=" btn btn-info btn-xs" title="Next Lib >> {{libraries.name}}">
<i class="fa fa-chevron-right fa-fw"></i>
</button>
Run Code Online (Sandbox Code Playgroud)
只是想知道如何实现此功能?任何输入?
我一直在阅读Angular2新的Forms API,似乎表单上有两种方法,一种是模板驱动形式,另一种是反应式或模型驱动型.
我想知道两者之间的实际差异,不是语法上的差异(显然),而是实际用途,哪种方法在不同情况下有更多好处.另外,选择其中一个是否有性能提升?如果是,为什么?
我正在尝试将Angular 5.2应用程序更新为Angular 6.我成功地遵循了Angular更新指南中的说明(包括更新angular-cli到v6),现在我正在尝试通过
ng serve --env=local
Run Code Online (Sandbox Code Playgroud)
但这给了我错误:
未知选项:' - env'
我使用多个环境(dev/local/prod),这就是它在Angular 5.2中的工作方式.如何在Angular 6中设置环境?
我刚刚开始乱用Angular 2,我想知道是否有人能告诉我从元素中动态添加和删除事件监听器的最佳方法.
我有一个组件设置.当单击模板中的某个元素时,我想为mousemove同一模板的另一个元素添加一个监听器.然后,我想在单击第三个元素时删除此侦听器.
我有点使用普通的Javascript来抓取元素,然后调用标准,addEventListener()但我想知道是否有更多的" Angular2.0 "方式,我应该调查.
我正在尝试测试我的角度4.1.0组件 -
export class CellComponent implements OnInit {
lines: Observable<Array<ILine>>;
@Input() dep: string;
@Input() embedded: boolean;
@Input() dashboard: boolean;
constructor(
public dataService: CellService,
private route: ActivatedRoute,
private router: Router, private store: Store<AppStore>) {
}
}
Run Code Online (Sandbox Code Playgroud)
但是,一个简单的"应该创建"测试会引发这个神秘的错误......
NetworkError:无法在'XMLHttpRequest'上执行'send':无法加载'ng:///DynamicTestModule/module.ngfactory.js'.
所以我发现了这个问题,这表明问题是组件有@Input)_没有设置的参数,但是,如果我像这样修改我的测试:
it('should create', inject([CellComponent], (cmp: CellComponent) => {
cmp.dep = '';
cmp.embedded = false;
cmp.dashboard = false;
expect(cmp).toBeTruthy();
}));
Run Code Online (Sandbox Code Playgroud)
然后我仍然得到相同的问题,同样,如果我@Input()从组件中删除注释,仍然没有区别.我怎样才能通过这些测试?
我想用角度cli创建一个角度2 App
我写的是cmd:
npm install angular-cli -g
然后:
ng firstngapp
我不明白这个问题
我正在尝试使用TypeScript和Angular应用程序运行dev服务器,而不是每次都转换ts文件.我发现我可以运行,ts-node但我也想观看.ts文件并重新加载应用程序/服务器,就像我用gulp watch这样的东西.
我已经读过,当引导应该让所有孩子共享相同的实例时注入,但我的主要和头部组件(主应用程序包括头部件和路由器出口)都获得了我的服务的单独实例.
我有一个FacebookService,用于调用facebook javascript api和一个使用FacebookService的UserService.这是我的引导程序:
bootstrap(MainAppComponent, [ROUTER_PROVIDERS, UserService, FacebookService]);
Run Code Online (Sandbox Code Playgroud)
从我的日志记录看起来,引导调用结束,然后我看到FacebookService然后在每个构造函数运行的代码,MainAppComponent,HeaderComponent和DefaultComponent之前创建UserService:
ng serve通过开发服务器提供Angular项目
npm start运行在其"scripts"对象的包的"start"属性中指定的任意命令.如果在"scripts"对象上未指定"start"属性,则它将运行节点server.js.
它似乎ng serve启动了嵌入式服务器,而npm start启动了Node服务器.
有人可以对它有所启发吗?
这些是我的文件。我收到此错误有人可以帮助我。
Error: src/app/app.component.html:5:123 - error TS4111: Property 'fName' comes from an index signature, so it must be accessed with ['fName'].
<input id="name" type="text" formControlName="fName" class="form-control" [ngClass]="{'is-invalid':submitted && f.fName.errors}"/>
Run Code Online (Sandbox Code Playgroud)
组件.html
<form [formGroup]="surveyForm" (ngSubmit)="onSubmit()">
<div>
<label>Name:</label>
<input id="name" type="text" formControlName="fName" class="form-control" [ngClass]="{'is-invalid':submitted && f.fName.errors}"/>
<div *ngIf="submitted && f.fName.errors" class="form-control">first name is required</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
组件.ts
import { Component, OnInit } from '@angular/core';
import { FormControl, FormBuilder, FormGroup, Validators} from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements …Run Code Online (Sandbox Code Playgroud) angular ×10
angular-cli ×4
typescript ×2
angular6 ×1
components ×1
gulp ×1
nodemon ×1
npm ×1
unit-testing ×1