我遵循了Angular 2快速入门指南,但收到以下错误:
在实例化令牌(AppView)期间出错!ORIGINAL ERROR:错误:找不到MyAppComponent的模板
这是相关代码:
import {Component, View} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser'
// Note I've changed Template to View here as I think it is a typo
....
@View({
template: '<h1>Hello {{ name }}</h1>'
})
....
Run Code Online (Sandbox Code Playgroud)
遵循Duncan Booth的建议http://blog.ionic.io/angular-2-series-introduction/我做了以下更改,一切正常:
import {Component, Template} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
....
@Template({
inline: "<h1>Hello {{ name }}</h1>"
})
....
Run Code Online (Sandbox Code Playgroud)
但在相同的链路yesimahuman的评论中提到,"观是新的语法",这似乎是这种情况如所示Plunker从角2分步指南.
那么为什么Quickstart代码会抛出错误,什么是正确的修复?
所以我正在开发一个Angular2应用程序.我有一张表,其中每条记录代表一名学生,并包含一个复选框
<input class="mycheckbox" type="checkbox" [value]='student.StudentId'>
Run Code Online (Sandbox Code Playgroud)
在某些时候,用户将点击一个需要获取所有选中复选框值的按钮.
我不确定应该由谁来解决这个问题.
一个想法是每个学生都有一个或不是被检查的值.这必须通过双向绑定来完成.
然而,这意味着每次你必须通过所有学生
这是最好的选择吗?有没有匹配以下JQuery的东西:
$('.mycheckbox:checked').each(function(){
Run Code Online (Sandbox Code Playgroud) 有点混淆如何在angular2 beta中使用Forms(模板或模态驱动froms).
目前我正在使用模态驱动的表单,但在这里得到一些错误是我的form.html:
<form [ngFormModel]="demo">
<input type="text" [ngFormControl]="demo.controls['name']">
<input type="text" [ngFormControl]="demo.controls['batch']">
<div>
<input type="radio" [ngFormControl]="demo.controls['radio']" name="status" value="true"> Active
<input type="radio" [ngFormControl]="demo.controls['radio']" name="status" value="false">Inactive
</div>
<div>
<input type="checkbox" [ngFormControl]="demo.controls['checkbox']" name="one" value="one"> one
<input type="checkbox" [ngFormControl]="demo.controls['checkbox']" name="two" value="two">two
</div>
<select [ngFormControl]="demo.controls['select']">
<option value="one">Oone</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
</select>
<button type="button" class="btn btn-primary btn-lg" data-dismiss="modal" (click)="demoSubmit(demo.value)">Done</button>
</form>
Run Code Online (Sandbox Code Playgroud)
和form.ts文件在这里:
import {Component, View} from 'angular2/core';
import {FORM_DIRECTIVES, CORE_DIRECTIVES, FormBuilder, Control, ControlGroup} from 'angular2/common';
import {ROUTER_DIRECTIVES} from 'angular2/router';
@Component({
selectro: 'Form',
templateUrl: 'src/components/form/form.html',
directives: …Run Code Online (Sandbox Code Playgroud) 我的 HTML 部分是:
<li *ngIf="action==null" id="list_icon"><a href="#" id="anchor"><i class={{icon}}></i> {{name}} {{color}}</a></li>
<li *ngIf="action!=null" id="list_icon" class="active"><span id="anchor"><i class={{icon}}></i> {{name}}</span></li>
Run Code Online (Sandbox Code Playgroud)
和CSS是:
li a{
background-color: red !important;
border: 1px solid red !important;
}
li a:before{
border-left-color: red !important;
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,我想在Css中使用颜色,如下所示:
li a{background-color: {{color}} !important;}
Run Code Online (Sandbox Code Playgroud)
我的 {{color}} 数据来自我的控制器或类。{{color}} 显示在模板上,但在我的风格中不起作用。有没有其他方法可以通过角度数据动态给出样式。或者我的代码需要一些更正?
我正在尝试使用 angular2 实现 singin 功能,也从这里阅读官方文档,但不明白流程是如何进行的。我的问题是
任何建议将不胜感激。
PS:到目前为止,我正在此 URL 上点击 Post 请求
let url = 'http://twitter.com/oauth/request_token?oauth_callback=http%3A%2F%2Fgoogle.com%2Ftwittercallback&oauth_consumer_key=my_consumer_key&oauth_nonce=ea9ec8429b68d6b77cd5600adbbb0456&oauth_signature=F1Li3tvehgcraF8DMJ7OyxO4w9Y&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1318467427&oauth_version=1.0';
Run Code Online (Sandbox Code Playgroud)
但抛出错误状态代码307。
我也尝试过使用ng2-twitter包但不起作用。
我们在当前项目中使用ngrx和Angular2.基本上ngrx是Redux的反应式扩展.ngrx提供单一的事实来源,数据可以从任何地方访问.
我们可以使用全局服务处理所有这些场景,但是为什么要编写已经可用和测试的相同代码.
我正在尝试使用TypeScript启动基本的Angular 2(beta 2)应用程序.我有以下app.ts文件(从Angular的最新设置指南中复制)
import {Component, View, bootstrap} from 'angular2/angular2';
@Component({
selector: 'app'
})
@View({
template: `
<div></div>
`
})
class AppComponent {
constructor() {}
}
bootstrap(AppComponent);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试编译它时,我得到了错误
错误TS2307:找不到模块'angular2/angular2'.
如果我改为使用在其他一些资源上找到的格式angular2/core而不是angular2/angular2像
import {Component, View, bootstrap} from 'angular2/core';
Run Code Online (Sandbox Code Playgroud)
我收到错误
错误TS2305:模块'"node_modules/angular2/core"'没有导出成员'bootstrap'.
我应该怎么做才能导入所有这些?
EventEmitter使用bootstrap模式处理angular2 ,但每当我通过子组件的事件传递一些参数时,只有在Bootstrap模式的情况下,角度才能解决纠正参数,否则一切正常.为什么?我做错了什么?
调用子组件编码(父组件) -
<ul>
<li *ngFor='#value of abc'>
<child-component (everySecond)="everySecond(value)"></child-component>{{view}}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
子组件编码 -
<div class="modal fade" id="delete_category" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header modal_header_color">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Delete</h4>
</div>
<div class="modal-body">
<div class="row margin_both">
<div class="col-md-12">
<div class="row form-group text-center">
<span>Are you sure you want to Delete !</span>
</div>
<div class="row form-group">
<div class="text-center">
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" (click)='call()' data-dismiss="modal">Delete</button> //not working
</div>
</div>
</div>
</div>
</div>
</div>
</div> …Run Code Online (Sandbox Code Playgroud) 如何使用嵌套字段创建表单,我知道formArray在angular2 RC中,但有点混淆如何正确使用它?假设我有一个这样的形式
// Main Form with formArray named as `global_modifier`
this.myForm = this._fb.group({
.......
name: ['', []],
global_modifier: this._fb.array([
this.initGlobalModifiers()
])
....
});
removeModifier(i: number) {
const control = <FormArray>this.myForm.controls['global_modifier'];
control.removeAt(i);
}
addModifier() {
const control = <FormArray>this.myForm.controls['global_modifier'];
control.push(this.initGlobalModifiers());
}
/*global_modifier function having nested fields named `items` .....*/
initGlobalModifiers() {
return this._fb.group({
.....
modifier_title: ['', []],
items: this._fb.array([
this.initItems()
])
.........
});
}
removeItem(i: number) {
const control = <FormArray>this.myForm.controls['items'];
control.removeAt(i);
}
addItem() {
const control = <FormArray>this.myForm.controls['items']; …Run Code Online (Sandbox Code Playgroud) angular ×8
angularjs ×1
checkbox ×1
css ×1
data-binding ×1
ethereum ×1
eventemitter ×1
jquery ×1
ngrx ×1
two-way ×1
typescript ×1