如何自动对焦输入元素?与此问题类似,但与AngularDart不同.像这样的东西:
<input type="text" [(ngModel)]="title" [focus] />
//or
<input type="text" [(ngModel)]="title" autofocus />
Run Code Online (Sandbox Code Playgroud)
Angular2是否支持此功能?
最近的问题是这个问题,但是有没有更简单/更简单的解决方案,因为我没有"输入框列表".在提供的链接*ngFor="#input of inputs"中使用,但我在控件模板中只有1个输入.
当我查看Angular2文档时,我找不到像Angular1的ngResource那样的任何REST辅助模块.我发现它在Angular1中非常有用,所以我想在Angular2中有类似的东西,但我唯一能找到的东西是'angular2/http'它不包含任何类似的东西(或者我的搜索不够好?).
虽然很明显我自己很容易实现类似的服务,Angular2团队是否有任何现成的模块,或者是否会有一个?
app
|-plugins
|-plugin1
|-config.json
|-plugin1.module.ts
|-plugin1.component.ts
|-plugin2
|-config.json
|-plugin2.module.ts
|-plugin2.component.ts
Run Code Online (Sandbox Code Playgroud)
如上所示,我有"app/plugins"文件夹,其中包含插件.每个插件将包含一个"config.json"文件,它将告诉一些配置,包括 -
{
path: "feature1",
moduleFile: "feature1.module",
moduleClassName: "Feature1Module"
}
Run Code Online (Sandbox Code Playgroud)
所以我想要的是,在应用程序引导之前,它将扫描"app/plugins"文件夹并加载所有插件配置,并懒惰地注册所有模块路由.对于上面的例子,路线将是
{
path: "feature1",
loadChildren: "app/plugins/plugin1/plugin1.module#Plugin1Module"
}
Run Code Online (Sandbox Code Playgroud)
这样,我们可以将新插件放入插件文件夹并刷新应用程序,我们新删除的插件已启动并运行.
谁知道我怎么能做到这一点?
注意:我在angular2最新(2.1.0)
一旦用户成功完成,我正在尝试显示导航栏.
例如:
如何在"LoginComponent"中的"AppComponent"中更改"showMenu"属性?重要提示:我正在使用路线.
app.ts:
@Component({
selector: 'app',
template: `<div *ngIf="showMenu">
<fnd-menu-nav></fnd-menu-nav>
</div>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES, MenuNavComponent]
})
@RouteConfig([
{ path: '/login', name: 'Login', component: LoginComponent, useAsDefault: true },
{ path: '/welcome', name: 'Welcome', component: WelcomeComponent }
])
export class AppComponent {
public showMenu : boolean;
}
Run Code Online (Sandbox Code Playgroud)
login.component.ts:
@Component({
selector: 'fnd-login',
templateUrl: './fnd/login/components/login.component.html',
providers: [LoginService]
})
export class LoginComponent {
/* .. other properties */
constructor(private _router: Router, private _loginService: LoginService ) {
}
/* .. other methods */
/* …Run Code Online (Sandbox Code Playgroud) ng-change = "ControllerName.functionName()"
在这里,我想再添加一个功能.我怎样才能做到这一点 ?
提前致谢.
我正在开发一个简单的Angular 2应用程序,但我无法重置ngForm但保留默认值:
预期的行为是单击"重置"时,输入框将重置为默认值(在本例中为"默认")以及返回默认值的所有角度特定类(即ng-untouched,ng-pristine,等等)
我所看到的是默认值也被清除,即使我在重置表单后明确设置它也是如此
以下代码段:
HTML:
<form (ngSubmit)="onTrainSearchClick()" novalidate #trainForm="ngForm">
<input type="text" [(ngModel)]="id" name="someId"/>
<button type="button" (click)="reset(trainForm)">Reset</button>
<button type="submit">Search</button>
</form>
Run Code Online (Sandbox Code Playgroud)
TypeScript(省略了导入和@Component):
export class TrainSearchTestComponent implements OnInit {
id: string = 'DEFUALT';
constructor() { }
ngOnInit() { }
onTrainSearchClick(){ }
reset(form: NgForm){
form.resetForm();
this.id = 'DEFUALT';
}
}
Run Code Online (Sandbox Code Playgroud) 我不确定与Typeular本身有关的Angular 2或更多问题.但无论如何,我有一个发射对象的组件
<grid" (gridButtonClickEvent)="gridEvent($event)"></grid>
Run Code Online (Sandbox Code Playgroud)
以下是我如何捕捉这一事件
private gridEvent(event) {
console.log(event);
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的事件格式.
{Key: value}
Run Code Online (Sandbox Code Playgroud)
所以基本上它是一个简单的对象.我想用名称调用一个函数Key并传递一个value参数,它怎么可能?对象Key会有所不同,但我知道我的组件中所有可能的变体和已注册的函数.
private Key() {}
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样的事情
private gridEvent(event) {
let eventName = Object.keys(event)[0];
window[eventName]();
}
Run Code Online (Sandbox Code Playgroud)
但它说
window[eventName] is not a function
Run Code Online (Sandbox Code Playgroud) 我可以在单个文件中合并枚举声明,例如
export enum Test {
value1 = <any>'value1',
value2 = <any>'value2'
}
export enum Test {
value3 = <any>'value3'
}
Run Code Online (Sandbox Code Playgroud)
这样做很好,但我的意图是有一个共享的枚举,我可以在以后扩展,例如
// test.enum.ts
export enum Test {
value1 = <any>'value1',
value2 = <any>'value2'
}
// place-to-extend-enum.ts
import { Test } from './test.enum';
export enum Test {
value3 = <any>'value3'
}
Run Code Online (Sandbox Code Playgroud)
我得到的是
合并声明'Test'中的个别声明必须全部导出或全部导出.
有没有办法实现理想的行为?
我正在使用角度2表单验证,我在文本框中设置了所需的验证,当我在文本框中输入任何内容时,它显示所需的错误消息它是可以的但是当我只输入空格时它不会显示所需的错误消息,这意味着角度2不修剪模型值.
在角度1.x中,它会自动修剪模型值,但在角度2中,我看不到此功能.
angular ×8
typescript ×6
angular-cli ×1
angularjs ×1
enums ×1
eventemitter ×1
forms ×1
function ×1
javascript ×1
ngresource ×1