你能帮忙吗?刚开始使用Angular 2并遇到以下问题.
我的组件如下:
@Component({
selector: 'myapp',
inputs: ['mynumber']
})
@View({
template: `<p>The next number is {{ mynumber + 1 }}</p>'
})
export class App {
mynumber: number;
}
bootstrap(App);
Run Code Online (Sandbox Code Playgroud)
在我的HTML中:
<myapp [mynumber]='41'></myapp>
Run Code Online (Sandbox Code Playgroud)
但是在运行时,我得到以下内容:
下一个号码是 NaN
它看起来很简单,但我遗漏了一些东西.我想要实现的是将应用程序外部的值传递给它.
谢谢.
我正在再次尝试将参数传递给我的应用程序.从RC5开始,我必须使用ngModule.(此解决方案:自从RC5以来,将asp.net服务器参数传递给Angular 2应用程序不再有效)
如何将参数传递给ngModule?
index.html的:
<script>
System.import('app').then(module => module.main('This is RIGHT'),
console.error.bind(console)
);
</script>
Run Code Online (Sandbox Code Playgroud)
main.ts:
import { browserDynamicPlatform } from '@angular/platform-browser-dynamic';
import { provide } from '@angular/core';
import { AppModule } from './app.module';
export function main(test: string) {
browserDynamicPlatform().bootstrapModule(AppModule, [{ providers: provide('Test', { useValue: test, }) }]);
}
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { NgModule, provide } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule
],
declarations: [ …Run Code Online (Sandbox Code Playgroud) 我在设置Input属性时遇到问题.我正在试图做的是通过从app.component.ts称为值passBool并设置属性的nextComponent称为receivedBool.
这是我的代码:
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<nextComponent [receivedBool]="passBool"></nextComponent>
`
})
export class AppComponent {
//Variables
passBool: Boolean = true;
constructor(){
console.log('The boolean value we are trying to pass is: ' + this.passBool)
}
}
Run Code Online (Sandbox Code Playgroud)
nextComponent.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'nextComponent',
template: `<i> </i> `
})
export class NextComponent {
@Input() receivedBool: Boolean = false;
constructor () {
console.log('The boolen value we …Run Code Online (Sandbox Code Playgroud) angular ×3