declare关键字的目的是什么?
type Callback = (err: Error | String, data: Array<CalledBackData>) => void;
Run Code Online (Sandbox Code Playgroud)
与
declare type Callback = (err: Error | String, data:Array<CalledBackData>) => void;
Run Code Online (Sandbox Code Playgroud)
找不到解释declareTS中关键字用途的文档.
无法解析指定值或超出范围
当我得到我的对象时,我用管道格式化一个数字,但它返回此警告并且不显示该值。如果我删除它,它就会显示。
这不显示该值
<input name="value" [ngModel]="value | number : '1.2-2'"/>
Run Code Online (Sandbox Code Playgroud)
这将显示该值
<input name="value" [ngModel]="value"/>
Run Code Online (Sandbox Code Playgroud)
TS 这里我在列表中选择对象后通过它的 id 获取它。
ngOnInit(){
this.get();
}
get() {
this.service.get(this.id).subscribe(
(data) => {
this.object = data;
this.name = this.object.name;
this.value = this.object.value;
},
(error) => {
console.log(error);
}
);
}
Run Code Online (Sandbox Code Playgroud)
该值是一个数字,我在控制台中得到它没有任何问题。
我有一个需要授权的州.我听的$stateChangeStart事件,如果toState.data.protected和用户无权我打电话e.preventDefault()和$state.go('login').
当我在根URL中打开应用程序时,我会自动重定向到受保护状态.这会导致10 $ digest循环,当我在根URL中打开应用程序时,我最终处于登录状态,并且我会自动重定向到受保护状态.
Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
请参阅此plnkr:http://plnkr.co/edit/1voh7m?p = preview
我成功地使用角度为1.2.26的不同项目中的类似代码,没有错误.
示例代码 angular 1.4.1, ui.router 0.2.15:
//config block
$urlRouterProvider.otherwise('/main');
$stateProvider
.state('main', {
url: '/main',
templateUrl: 'main.html',
controller: 'MainController as main',
data: {'protected': true}
})
.state('login', {
url: '/login',
templateUrl: 'login.html',
controller: 'LoginController as login'
});
// in a run block
$rootScope.$on("$stateChangeStart", function (event, toState) {
if (!event.defaultPrevented && toState.data &&
toState.data.protected) {
// the …Run Code Online (Sandbox Code Playgroud) 我想使用角度数据绑定和 Input 装饰器将输入值从一个组件获取到另一个给定的子组件。
我有一个最小的例子来向你展示我想如何完成这个任务:
父模板:
<h4>Passing value of input element to child component:</h4>
<input [ngModel]="name" (ngModelChange)="name = $event">
<p>{{name}}</p>
<hello [name]="name"></hello>
Run Code Online (Sandbox Code Playgroud)
父组件:
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = '';
}
Run Code Online (Sandbox Code Playgroud)
子组件:
@Component({
selector: 'hello',
template: `<h4>Passed : "{{ name }}" to child component!</h4>`,
styles: [`h1 { font-family: Lato; }`]
})
export class HelloComponent {
@Input() name: string;
}
Run Code Online (Sandbox Code Playgroud)
这似乎在 stackblitz 上工作得很好:https ://stackblitz.com/edit/angular-pggcbd
但我的本地打字稿编译器响应:
Cannot find name 'Input'.ts(2304)
并标记@Input() …