小编Mil*_*ilo的帖子

Angular 2简单的方法来进行确认对话

是否有任何不那么复杂的方法在角度2中进行确认对话,想法是点击一个项目,然后显示一个弹出窗口或模态以确认其删除,我尝试角度2模态从这里angular2-modal,但如果你确认或取消它,我不知道如何做到这一点.点击功能工作正常,唯一的问题是我不太清楚如何使用它.我还有另一个带有相同插件的模态,与我使用的不同.

this.modal.open(MyComponent);
Run Code Online (Sandbox Code Playgroud)

而且我不想创建另一个组件只是为了显示一个确认框,这就是我要问的原因.

angular

54
推荐指数
6
解决办法
16万
查看次数

模型表单的自定义错误消息

我可以看到在使用表单时如何向字段添加错误消息,但是模型表单呢?

这是我的测试模型

class Author(models.Model):
    first_name = models.CharField(max_length=125)
    last_name = models.CharField(max_length=125)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
Run Code Online (Sandbox Code Playgroud)

我的模特形式

class AuthorForm(forms.ModelForm):
    class Meta:
        model = Author
Run Code Online (Sandbox Code Playgroud)

字段:first_name和last_name上的错误消息是"此字段是必需的".如何在模型表单中更改它?

django django-forms

44
推荐指数
6
解决办法
4万
查看次数

Angular2无法找到命名空间'google'

我正在使用angular2-google-mapsAngular2的最新版本.我试图将一些本地地图组件功能转换为自己文件中的服务maps.service.ts.例如:

map.component.ts

getGeoLocation(lat: number, lng: number) {
if (navigator.geolocation) {
    let geocoder = new google.maps.Geocoder();
    let latlng = new google.maps.LatLng(lat, lng);
    let request = { latLng: latlng };
    geocoder.geocode(request, (results, status) => {
      if (status == google.maps.GeocoderStatus.OK) {
        let result = results[0];
        if (result != null) {
          this.fillInputs(result.formatted_address);
        } else {
          alert("No address available!");
        }
      }
    });
}
}
Run Code Online (Sandbox Code Playgroud)

变成这样的东西: maps.service.ts

getGeoLocation(lat: number, lng: number): Observable<google.maps.GeocoderResult[]> {
    let geocoder = new google.maps.Geocoder();
    let latlng = new …
Run Code Online (Sandbox Code Playgroud)

google-maps typescript angular-cli angular2-google-maps angular

29
推荐指数
5
解决办法
3万
查看次数

为什么我不能在异步方法中调试代码?

我实际上开始尝试了解有关MongoDB的更多信息,但是我已经挂断了.NET等待/异步的东西.我正在尝试实现MongoDB 网站上显示的代码.我不得不稍微修改它,所以我可以让我的程序编译.我知道有以下我的控制台应用程序.

protected static IMongoClient _client;
protected static IMongoDatabase _database;

static void Main(string[] args)
{
    _client = new MongoClient();
    _database = _client.GetDatabase("test");

    GetDataAsync();
}

private static async void GetDataAsync() //method added by me.
{
    int x = await GetData();
}

private static async Task<int> GetData()
{
    var collection = _database.GetCollection<BsonDocument>("restaurants");
    var filter = new BsonDocument();
    var count = 0;
    Func<int> task = () => count; //added by me.
    var result = new Task<int>(task); //added by me.
    using (var cursor …
Run Code Online (Sandbox Code Playgroud)

c# asynchronous mongodb

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

Mvc ViewBag - 无法将null转换为'bool',因为它是一个不可为空的值类型

我想在生成某个视图时在控制器中将bool设置为true,然后相应地更改视图的标题.这应该是简单的,但我得到:

无法对空引用执行运行时绑定异常详细信息:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法对空引用执行运行时绑定

我正在做的就是控制器:

[AllowAnonymous]
public ActionResult Register()
{
    ViewBag.IsRegistration = true;
    return View();
}
Run Code Online (Sandbox Code Playgroud)

然后在视图中:

@if (ViewBag.IsRegistration)
{
    <legend>Register using another service.</legend>
}
else
{
    <legend>Use another service to log in.</legend>
}
Run Code Online (Sandbox Code Playgroud)

但它失败了:

@if (ViewBag.IsRegistration)
Run Code Online (Sandbox Code Playgroud)

UPDATE

相关控制器代码:

[AllowAnonymous]
public ActionResult Register()
{
    ViewBag.IsRegistration = "true";
    return View();
}
Run Code Online (Sandbox Code Playgroud)

注册视图:

@model Mvc.Models.RegisterViewModel
@{
     Layout = "~/Views/Shared/_AccountLayout.cshtml";
     ViewBag.Title = "Register";
}

<hgroup class="title">
    <h1>@ViewBag.Title.</h1>
</hgroup>

<div class="row">
<div class="col-lg-6">
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()

        <fieldset class="form-horizontal">
            <legend>Create a new account.</legend>
            <div class="control-group"> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc razor asp.net-mvc-4

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

在 EsLint 中禁用 Reactjs 中的“react / jsx-props-no-spreading”错误

安装 EsLint 后,我​​看到的错误之一如下:

Prop spreading is forbiddeneslint(react/jsx-props-no-spreading)

I want to create a rule in the EsLint configuration to ignore this error but the examples I found do not work.

This is the format to create a global exception:

...
"react/jsx-props-no-spreading": [{
    "html": "ignore" / "enforce",
    "custom": "ignore" / "enforce",
    "exceptions": [<string>]
}]
...
Run Code Online (Sandbox Code Playgroud)

And this is the format to create an exception in a specific file:

{
  "rules": {...},
  "overrides": [
    {
      "files": ["*-test.js","*.spec.js"],
      "rules": {
        "no-unused-expressions": "off"
      }
    } …
Run Code Online (Sandbox Code Playgroud)

reactjs eslint redux

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

Angular2可观察定时器条件

我有一个计时器:

initiateTimer() {
    if (this.timerSub)
        this.destroyTimer();

    let timer = TimerObservable.create(0, 1000);
    this.timerSub = timer.subscribe(t => {
        this.secondTicks = t
    });
}
Run Code Online (Sandbox Code Playgroud)

如何在60分钟后向用户添加弹出窗口?我已经尝试过看几个问题(这个这个),但它不是为了点击我.RxJS模式还是新手......

timer observable rxjs angular2-observables angular

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

在VBA中使用带有可见单元格的CountIf

我试图CountIf在可见细胞上的vba中使用一个函数来计算所有可见的单元格yes,有25个,但是我得到了错误

无法获得班级的CountIf财产WorksheetFunction

它突出显示returnCount,不确定是否也有错误myrange,任何帮助将不胜感激.

Set myrange = _
Range("D4",Range("D4").End(xlDown)).SpecialCells(xlCellTypeVisible)

returnCount = WorksheetFunction.CountIf(myrange, "yes")
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

10
推荐指数
1
解决办法
1423
查看次数

如何禁用FormGroup中的所有FormControls

我有这种反应性角形结构

myForm: FormGroup;
Personal: FormGroup;
FIRST_NAME: FormControl;
LAST_NAME: FormControl;
ngOnInit(): void {
    this.createFormControls();
    this.createForm();
}
createFormControls() {
    this.FIRST_NAME = new FormControl('', [Validators.required]);
    this.LAST_NAME = new FormControl('', [Validators.required]);
}
createForm(): void {
    this.myForm = this.fb.group({
        Personal: this.fb.group({
            FIRST_NAME: this.FIRST_NAME,
            LAST_NAME: this.LAST_NAME,
        })
    })
}
Run Code Online (Sandbox Code Playgroud)

如果我做

this.FIRST_NAME.disable();
Run Code Online (Sandbox Code Playgroud)

它禁用FormControl

如何禁用Personal FormGroup中的所有FormControls

angular angular-reactive-forms formgroups

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

perl6 set opertions中用户定义的比较函数

Perl6文档表明,当比较一组中的两个项目时,===使用.这是来自perl6文档的引用:

允许任何类型的对象/值作为设置元素.在集合中,每个元素都保证是唯一的(在某种意义上,没有两个元素会与===运算符进行正比较)

我想知道是否可以使用用户定义的函数而不是===?例如,我如何使用~~而不是===确定集合中的2个元素是否"相等".

我试图解决的问题是:集合A有一些名字和一些姓氏,但是所有的小写和没有标点符号,而集合B有许多名字和姓氏以任何顺序混合,并且那里可能是名称附带的标点符号,可能是大写或小写.我想知道集合A中的人(表示为具有一个特定名字和姓氏的A的子集)是否出现在集合B中.在这种情况下,===由于集合B中的字母案例和标点符号,我无法使用.

如果我可以使用~~而不是===,那么问题就会简单得多,因为我只需要确定A的子集是否也是B的子集~~.这类似于我之前提到的"置换匹配"问题.

非常感谢你 !

comparison set elements perl6

8
推荐指数
1
解决办法
140
查看次数