小编Sim*_*mon的帖子

错误:formControlName必须与父formGroup指令一起使用.您需要添加一个formGroup指令 - Angular反应形式

我有以下模板.我正试图掌握反应形式,但我遇到了问题.

<form [formGroup]="guestForm" novalidate>
    <div class="panel-body">
        <form>
            <div class="col-md-12 col-sm-12">
                <div class="form-group col-md-3 col-sm-6">
                    <label>First Name*  </label>
                    <input formControlName="firstname" type="text" class="form-control input-sm">
                </div>
            </div>
        </form>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

然后在我的组件中我有:

@Component({
    selector: 'guest-input',
    templateUrl: './guest-input.component.html',
})
export class GuestInputComponent implements OnInit {
    @Input()
    guest: Guest;

    guestForm: FormGroup;

    constructor(private _fb: FormBuilder) { }

    ngOnInit() {
        this.guestForm = this._fb.group({
            firstname: ['test', [Validators.required, Validators.minLength(3)]]
        });
    }
Run Code Online (Sandbox Code Playgroud)

这一切对我来说都很好,但由于某种原因,我得到:

错误:未捕获(在承诺中):错误:formControlName必须与父formGroup指令一起使用.您将要添加formGroup指令并将其传递给现有的FormGroup实例(您可以在类中创建一个).

我以为我已经在我的身上宣布了这一点<form>.

angular2-forms angular

21
推荐指数
2
解决办法
3万
查看次数

首先不识别mvc代码中的"启用 - 迁移"一词

我正在尝试在我的新mvc 4应用程序PM> Enable-Migrations -EnableAutomaticMigrations中第一次运行

我在说:

Enable-Migrations : The term 'Enable-Migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Enable-Migrations –EnableAutomaticMigrations
Run Code Online (Sandbox Code Playgroud)

我错过了什么?我已经安装了ef 5.

ef-code-first asp.net-mvc-4

13
推荐指数
2
解决办法
2万
查看次数

using contains而不是stringStartsWith knockout js

我对我的模型有所了解:

self.filteredItems = ko.computed(function () {
            var filter = this.filter().toLowerCase();

            if (!filter) {
                return this.sites();
            } else {
                return ko.utils.arrayFilter(this.sites(), function (item) {
                    return ko.utils.stringStartsWith(item.Name().toLowerCase(), filter);
                });
            }

        }, self);
Run Code Online (Sandbox Code Playgroud)

我用它来搜索我的页面而不是stringStartsWith我想要某种类型的.contains,所以我得到的结果是我的searchterm包含在字符串中的任何地方而不是仅仅在开头.

我想这必须是一个非常常见的请求,但是找不到任何明显的东西.

有什么建议吗?

asp.net-mvc-4 knockout.js

9
推荐指数
1
解决办法
7302
查看次数

如何使用angular cli升级小角度版本的角度

这是一个简单的问题,但我很难通过Google找到答案......

我有一个角度4项目(使用angular cli创建),并希望使用刚刚在4.3中发布的http拦截器.

如何使用angular cli升级到此次要版本?

javascript node.js npm angular-cli angular

9
推荐指数
2
解决办法
2425
查看次数

通过param名称对ArgumentNullException进行单元测试

我有一个单元测试,并检查我的控制器构造函数的空异常为几个不同的服务.

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
Run Code Online (Sandbox Code Playgroud)

在我的控制器构造函数中,我有:

 if (routeCategoryServices == null)
    throw new ArgumentNullException("routeCategoryServices");

 if (routeProfileDataService == null)
    throw new ArgumentNullException("routeProfileDataService");
Run Code Online (Sandbox Code Playgroud)

我对每个进行了单元测试,但是如何区分这两者.我可以保持测试,因为任何一个检查都可能抛出null,所以我想通过param名称测试异常.

这可能吗?

c# unit-testing mstest dependency-injection

6
推荐指数
1
解决办法
7356
查看次数

在现有的webforms项目中使用bundle

我有一个现有的Web表单项目,现在使用.net 4.5.

使用nuget我添加了对system.web.omtimization的引用.

然后,我放在标题中,并尝试靠近我的页脚:

 <%: Scripts.Render("~/Scripts/CaseReview") %>
Run Code Online (Sandbox Code Playgroud)

我还将以下内容添加到global.asax:

BundleConfig.RegisterBundles(BundleTable.Bundles);
Run Code Online (Sandbox Code Playgroud)

我得到:当前上下文中不存在"脚本"这个名称

我可以使用捆绑webforms是吗?

如果是这样我做错了什么/不做什么?

c# webforms bundling-and-minification

5
推荐指数
1
解决办法
1070
查看次数

SASS 子选择器找不到目标

好的,所以我有以下 HTML(通过 angular 6)

<mat-tab-group class="mat-tab-group is-third-party">
<mat-tab-header class="mat-tab-header">
Run Code Online (Sandbox Code Playgroud)

然后我有以下 SASS,我正在尝试开始工作

 mat-tab-group {
      background-color: yellow;
      height: 100%;
      display: inherit; 

      &.is-third-party {
           background-color: blue;

           mat-tab-header {
                display: none !important;
           }
      }
Run Code Online (Sandbox Code Playgroud)

一切都工作到 isThirdParty (我得到了我添加的蓝色背景,看看到底发生了什么)

我已经尝试了各种组合来让 mat-tab-header 被击中,但它没有。我试过了 。对于类名、子选择器 > 以及我所做的任何事情,我都不会遇到 mat-tab-header 被击中并因此被隐藏。

我只涉足 SASS,有人能看到我做错了什么吗?更新:看我下面的图片,html 中有点膨胀,但你可以看到这个 SASS 的 HTML 看起来不错?

在此处输入图片说明

sass angular

3
推荐指数
1
解决办法
867
查看次数

为什么我从双倍到十进制时丢失数据

我有以下代码,我无法改变...

 public static decimal Convert(decimal value, Measurement currentMeasurement, Measurement targetMeasurement,  bool roundResult = true)
 {
     double result = Convert(System.Convert.ToDouble(value), currentMeasurement, targetMeasurement, roundResult);
     return System.Convert.ToDecimal(result);
 }
Run Code Online (Sandbox Code Playgroud)

现在result返回,-23.333333333333336但一旦转换为a decimal,它就变成了-23.3333333333333M.

我想decimal小号可以容纳更大的价值和人因此更准确所以我怎么丢失数据从去doubledecimal

c#

0
推荐指数
1
解决办法
114
查看次数

在控制器功能中未定义角度模板枚举

我在angular(4)app中有以下内容:

export enum RegisterAccomodationStatus {
    noFixedAbode = 1,
    sofaSurfing = 2,
    accommodation = 3,
    other = 4
}
Run Code Online (Sandbox Code Playgroud)

在我的模板中,我有:

<button (click)="setCurrentAccomStatus(attendance, registerAccomodationStatus.noFixedAbode)" type="button" class="btn btn-default">NFA</button>
<button (click)="setCurrentAccomStatus(attendance, registerAccomodationStatus.sofaSurfing)" type="button" class="btn btn-default">Sofa</button>
Run Code Online (Sandbox Code Playgroud)

我在我的组件中设置了一个属性:

registerAccomodationStatus: RegisterAccomodationStatus = RegisterAccomodationStatus.other;
Run Code Online (Sandbox Code Playgroud)

最后我的功能:

setCurrentAccomStatus(registerAttendance: RegisterAttendance, accomStatusId: RegisterAccomodationStatus) {
        console.log(accomStatusId);
        registerAttendance.accomodationStatus = accomStatusId;

        this.registerService.updateGuestAttendance(registerAttendance)
            .subscribe(registerAtt => registerAttendance = registerAtt);
    }
Run Code Online (Sandbox Code Playgroud)

当点击其中一个按钮时console.log(accomStatusId);,undefined我正在按照我在网上找到的示例来执行此操作.

我究竟做错了什么?

angular

0
推荐指数
1
解决办法
1529
查看次数

jquery没找到我的json值?

我从服务器端代码返回一些json.

console.log(data) 给我的是:

{
   "VRM": "DG70XSC",
   "Make": "FORD",
   "Model": "FOCUS ZETEC CLIMATE 116",
   "Body": "5 DOOR HATCHBACK",
   "Doors": "5 DOORS",
   "Seats": 5,
   "BodyDescription": "hatchback"
}
Run Code Online (Sandbox Code Playgroud)

为什么在这种情况下是console.log(data.BodyDescription)未定义?

我错过了什么吗?

jquery json

-3
推荐指数
1
解决办法
63
查看次数