我正在创建我的第一个Angular应用程序,我会弄清楚模块加载器的作用是什么.为什么我们需要它们?我试图在Google上搜索和搜索,我无法理解为什么我们需要安装其中一个来运行我们的应用程序?
仅仅用于import从节点模块加载东西是不够的?
我已经按照本教程(使用SystemJS),它让我使用systemjs.config.js文件:
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'transpiled', // 'dist',
'@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': …Run Code Online (Sandbox Code Playgroud) 我正在使用ReactiveFormsModuleAngular2来创建包含表单的组件.这是我的代码:
foo.component.ts:
constructor(fb: FormBuilder) {
this.myForm = fb.group({
'fullname': ['', Validators.required],
'gender': []
});
}
Run Code Online (Sandbox Code Playgroud)
foo.component.html(with [formControl]):
<div class="fields">
<div class="field">
<label>Fullname*</label>
<input type="text" [formControl]="myForm.controls.fullname"/>
</div>
</div>
<div class="inline fields">
<label for="gender">Gender</label>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="gender" checked="" tabindex="0" class="hidden" [formControl]="myForm.controls.gender">
<label>Male</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="gender" tabindex="0" class="hidden" [formControl]="myForm.controls.gender">
<label>Female</label>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
foo.component.html(with formControlName):
<div class="fields">
<div class="field">
<label>Fullname*</label>
<input type="text" …Run Code Online (Sandbox Code Playgroud) radio-button form-control angular2-forms angular2-formbuilder angular
如何更改选项菜单的索引图标?

我的意思是图标(3).
这是我的代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options, menu);
return true;
}
Run Code Online (Sandbox Code Playgroud)
这是XML文件:
<item android:id="@+id/Bugreport"
android:title="@string/option_bugreport" />
<item android:id="@+id/Info"
android:title="@string/option_info" />
<item android:id="@+id/About"
android:title="@string/option_about" />
Run Code Online (Sandbox Code Playgroud)
android android-menu android-icons android-optionsmenu android-actionbar
我应该为私有或受保护的方法编写JavaDoc 吗?私有变量怎么样?
我在Java书上看到了类示例,私有变量是JavaDoc.所以我无法理解JavaDoc 私有(或受保护)方法是否是一个好习惯.
使用ui-router-ng2而不是新的Angular2路由器有什么好处和缺点?在过去,我使用ui-router和Angular 1.x而不是使用ngRoute,因为我需要更好地支持嵌套状态/路由.
那么现在,Angular2呢?我想听听你的意见,以便我能评估这两个机会.
此外,搜索和搜索谷歌我发现ngrx /路由器,我不知道.你能告诉我Angular2 的内置路由器,Angular2和ngrx路由器的新ui路由器之间有什么区别吗?
我的应用程序显示了一张地图,我希望用户无法滑过某个区域.所以我试图添加边界,但它会使应用程序崩溃.这是工作代码:
public class MapViewer extends Activity implements OnInfoWindowClickListener {
private LatLng defaultLatLng = new LatLng(42.564241, 12.22759);
private GoogleMap map;
private int zoomLevel = 5;
private Database db = new Database(this);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapviewer);
try {
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
if (map != null) {
map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.getUiSettings().setRotateGesturesEnabled(false);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultLatLng, zoomLevel));
this.addMerchantMarkers(new MarkerOptions());
map.setOnInfoWindowClickListener(this);
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
@Override
public void onPause() {
if (map != null) {
map.setMyLocationEnabled(false);
map.setTrafficEnabled(false);
}
super.onPause();
} …Run Code Online (Sandbox Code Playgroud) 这是我的Angular2应用程序结构:
这是我的代码的一部分.以下是moduleAngular2应用程序的主要内容,它导入其路由规则和子模块(EdgeModule)并使用与某些页面相关的一些组件.
app.module.ts
@NgModule({
declarations: [
AppComponent,
PageNotFoundComponent,
LoginComponent
],
imports: [
...
appRouting,
EdgeModule
],
providers: [
appRoutingProviders,
LoginService
],
bootstrap: [AppComponent]
})
export class AppModule {
}
Run Code Online (Sandbox Code Playgroud)
以下是主模块的路由规则.它有登录页面和页面找不到的路径.
app.routing.ts
const appRoutes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: '**', component: PageNotFoundComponent }
];
export const appRoutingProviders: any[] = [];
export const appRouting = RouterModule.forRoot(appRoutes, { useHash: true });
Run Code Online (Sandbox Code Playgroud)
这是EdgeModule声明它使用的组件并导入自己的路由规则和2个子模块(FirstSectionModule和SecondSectionModule).
edge.module.ts
@NgModule({
declarations: [
EdgeComponent, …Run Code Online (Sandbox Code Playgroud) url-routing nested-routes angular2-routing angular2-modules angular
正如Angular 文档所说,我们可以formControlName在表单中使用:
<h2>Hero Detail</h2>
<h3><i>FormControl in a FormGroup</i></h3>
<form [formGroup]="heroForm" novalidate>
<div class="form-group">
<label class="center-block">Name:
<input class="form-control" formControlName="name">
</label>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
正如他们所说...
没有父FormGroup,[formControl] ="name"之前工作,因为该指令可以单独使用,也就是说,它可以在不在FormGroup中的情况下工作.对于父FormGroup,名称输入需要语法formControlName = name才能与类中的正确FormControl相关联.此语法告诉Angular查找父FormGroup,在本例中为heroForm,然后在该组内查找名为name的FormControl.
无论如何,几个月前我问这个,找出formControlName和之间有什么区别[formControl].
现在我的问题是:如何使用formControlName嵌套的FormGroups?
例如,如果我有以下表单结构:
this.myForm = fb.group({
'fullname': ['', Validators.required],
'gender': [],
'address': fb.group({
'street': [''],
'houseNumber': [''],
'postalCode': ['']
})
});
Run Code Online (Sandbox Code Playgroud)
使用"绑定"街道(或"houseNumber"或"postalCode")到相关HTML元素的正确方法是formControlName什么?
我form在Angular中创建了以下内容FormBuilder:
constructor(private fb: FormBuilder) {
this.myForm = fb.group({
'name': ['', [Validators.required],
'surname': ['', [Validators.required],
'email': ['', [validateEmail]],
'address': fb.group({
'street': [''],
'housenumber': [''],
'postcode': ['']
}, { validator: fullAddressValidator })
});
}
Run Code Online (Sandbox Code Playgroud)
是否存在以编程方式附加新字段(如FormControlnew或new)的FormGroup方法myForm?
我的意思是,如果我想按需或在某些条件下添加新字段,如何将项目添加到第一次创建的同一表单中constructor?
我创建了以下类:
export class MyItem {
public name: string;
public surname: string;
public category: string;
public address: string;
constructor();
constructor(name:string, surname: string, category: string, address?: string);
constructor(name:string, surname: string, category: string, address?: string) {
this.name = name;
this.surname = surname;
this.category = category;
this.address = address;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
过载签名与功能实现不兼容
我尝试了几种方法来重载构造函数,我尝试的最后一个是我在上面发布的(我从这里得到).
但我仍然得到同样的错误.我的代码出了什么问题?
constructor class constructor-overloading typescript angular
angular ×7
android ×2
forms ×2
url-routing ×2
android-menu ×1
class ×1
constructor ×1
form-control ×1
java ×1
javadoc ×1
ngrx ×1
node-modules ×1
private ×1
protected ×1
radio-button ×1
systemjs ×1
typescript ×1
webpack ×1