如何运行 StackBlitz 项目

huangapple go评论68阅读模式
英文:

How to run stackblitz project

问题

抱歉关于愚蠢问题的提问。

作为一个Angular初学者(还有StackBlitz),我创建了一个StackBlitz项目,以寻求关于Angular主题(响应式表单)的帮助。
链接

但我无法运行它。
我该怎么做?

谢谢

英文:

Sorry for the stupid question.

Beginner with angular (and stackblitz) I created a stackblitz project to ask for help on an angular subject (reactive forms)
https://stackblitz.com/edit/angular-4vdtbe?file=src%2Fselect%2Fselect.component.ts,src%2Fselect%2Fselect.component.html
But I can't run it.
How can I do that ?

Thanks

答案1

得分: 1

对不起,有很多问题,我刚刚修复了其中一些

  1. 首先,查看StackBlitz控制台,它可以帮助您查找问题
    如何运行 StackBlitz 项目

  2. index.html应该包含main.ts组件(具有选择器<my-app>),这就是为什么您需要在index.html中添加<my-app>的原因

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;我的应用&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;my-app&gt;&lt;/my-app&gt;
  &lt;/body&gt;
&lt;/html&gt;
  1. main.ts模板具有默认代码。添加您组件的选择器。导入您的SelectComponent
import { Component } from &#39;@angular/core&#39;;
import { CommonModule } from &#39;@angular/common&#39;;
import { bootstrapApplication } from &#39;@angular/platform-browser&#39;;
import { SelectComponent } from &#39;./select/select.component&#39;;

@Component({
  selector: &#39;my-app&#39;,
  standalone: true,
  imports: [CommonModule, SelectComponent],
  template: `
    &lt;app-select&gt;&lt;/app-select&gt;
  `,
})
export class App {
  name = &#39;Angular&#39;;
}

bootstrapApplication(App);
  1. select.component.ts,将您的组件设置为独立的,并导入必要的模块
import { CommonModule } from &#39;@angular/common&#39;;
import { Component, OnInit } from &#39;@angular/core&#39;;
import {
  FormArray,
  FormBuilder,
  FormGroup,
  FormsModule,
  ReactiveFormsModule,
} from &#39;@angular/forms&#39;;

export interface IDocument {
  id: string;
  label: string;
  maxQuantity: number;
}

@Component({
  selector: &#39;app-select&#39;,
  standalone: true,
  imports: [ReactiveFormsModule, FormsModule, CommonModule],
  templateUrl: &#39;./select.component.html&#39;,
  styleUrls: [&#39;./select.component.css&#39;],
})
....

5. 修复代码中的其他问题
在这里,有一个演示,在那里我删除了一些有问题的代码,以启动应用程序
https://stackblitz.com/edit/angular-wiskwl?file=src/select/select.component.ts

  [1]: https://i.stack.imgur.com/ThVK0.png

<details>
<summary>英文:</summary>

Sorry, there are many issues, i&#39;ve just fixed some of them

1. First, look at the stackblitz console, it helps you to look for issues 
[![Console][1]][1]

2. index.html should have main.ts component(which has selector &lt;my-app&gt;), that&#39;s why you need add &lt;my-app&gt; in index.html
```html
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;My app&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;my-app&gt;&lt;/my-app&gt;
  &lt;/body&gt;
&lt;/html&gt;
  1. main.ts template has default code. Add a selector of your component. Import your SelectComponent
import { Component } from &#39;@angular/core&#39;;
import { CommonModule } from &#39;@angular/common&#39;;
import { bootstrapApplication } from &#39;@angular/platform-browser&#39;;
import { SelectComponent } from &#39;./select/select.component&#39;;

@Component({
  selector: &#39;my-app&#39;,
  standalone: true,
  imports: [CommonModule, SelectComponent],
  template: `
    &lt;app-select&gt;&lt;/app-select&gt;
  `,
})
export class App {
  name = &#39;Angular&#39;;
}

bootstrapApplication(App);
  1. select.component.ts, make your component as standalone and import nessesary modules
import { CommonModule } from &#39;@angular/common&#39;;
import { Component, OnInit } from &#39;@angular/core&#39;;
import {
  FormArray,
  FormBuilder,
  FormGroup,
  FormsModule,
  ReactiveFormsModule,
} from &#39;@angular/forms&#39;;

export interface IDocument {
  id: string;
  label: string;
  maxQuantity: number;
}

@Component({
  selector: &#39;app-select&#39;,
  standalone: true,
  imports: [ReactiveFormsModule, FormsModule, CommonModule],
  templateUrl: &#39;./select.component.html&#39;,
  styleUrls: [&#39;./select.component.css&#39;],
})
....
  1. Fix other issues, with your code
    Here, a demo, there I cut some code(with issues) just to launch the application
    https://stackblitz.com/edit/angular-wiskwl?file=src/select/select.component.ts

huangapple
  • 本文由 发表于 2023年3月9日 23:50:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75686984.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定