小编nco*_*hen的帖子

替换出现的NSString - iPhone

我有一个很长的NSString,我试图替换特殊字符.我的部分字符串如下所示:

"veau (c\u00f4telette)","veau (filet)","agneau (gigot)","agneau (c\u00f4telette)","b**\u0153**uf (hach\u00e9)","porc (hach\u00e9)"
Run Code Online (Sandbox Code Playgroud)

我想用"oe"替换所有\ u0153.我试过了:

[response stringByReplacingOccurrencesOfString:@"\u0153" withString:@"oe"];
Run Code Online (Sandbox Code Playgroud)

但它不起作用....我不明白为什么!

iphone replace objective-c nsstring

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

是什么导致"control.registerOnChange不是函数"错误

我有一个使用反应形式方法的表格.表单在我的哈巴狗中创建如下:

form([formGroup]='form', novalidate='', (ngSubmit)='postSurvey(form.value, form.valid)')
Run Code Online (Sandbox Code Playgroud)

一切正常,除非我尝试FormArray在javascript部分中更改表单(即a ).我收到以下错误:

EXCEPTION: Error in http://localhost:8080/app/components/fillForm.template.html:0:326 caused by: control.registerOnChange is not a function
core.umd.js:3497 TypeError: control.registerOnChange is not a function
    at setUpControl (http://localhost:8080/node_modules/@angular/forms/bundles/forms.umd.js:1634:17)
    at eval (http://localhost:8080/node_modules/@angular/forms/bundles/forms.umd.js:4752:25)
    at Array.forEach (native)
    at FormGroupDirective._updateDomValue (http://localhost:8080/node_modules/@angular/forms/bundles/forms.umd.js:4747:29)
    at FormGroupDirective.ngOnChanges (http://localhost:8080/node_modules/@angular/forms/bundles/forms.umd.js:4616:22)
    at Wrapper_FormGroupDirective.ngDoCheck (/ReactiveFormsModule/FormGroupDirective/wrapper.ngfactory.js:30:18)
    at View_FillFormComponent2.detectChangesInternal (/AppModule/FillFormComponent/component.ngfactory.js:275:32)
    at View_FillFormComponent2.AppView.detectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12592:18)
    at View_FillFormComponent2.DebugAppView.detectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12739:48)
    at ViewContainer.detectChangesInNestedViews (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12850:41)
    at CompiledTemplate.proxyViewClass.View_FillFormComponent0.detectChangesInternal (/AppModule/FillFormComponent/component.ngfactory.js:64:14)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12592:18)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12739:48)
    at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12577:22)
    at CompiledTemplate.proxyViewClass.View_FillFormComponent_Host0.detectChangesInternal (/AppModule/FillFormComponent/host.ngfactory.js:29:19)
Run Code Online (Sandbox Code Playgroud)

我改变表单的代码非常复杂,我不能简化它或在plunker中重现它.不仅仅是直接找到解决方案(由于细节太少而太难),我想了解这个错误意味着什么?什么可能导致这个错误.

我已经发现错误发生[formGroup]='form'在我的HTML中.

任何建议都会有所帮助.

更新我已经在GitHub上的角度提交的问题,在这里 …

forms angular

32
推荐指数
6
解决办法
3万
查看次数

检测指令中输入值何时更改

我正试图检测指令中输入何时发生变化.我有以下指令:

import { ElementRef, Directive, Renderer} from '@angular/core';

@Directive({
    selector: '[number]',
    host: {"(input)": 'onInputChange($event)'}
})

export class Number {

    constructor(private element: ElementRef, private renderer: Renderer){

    }
    onInputChange(event){
        console.log('test');
    }
}
Run Code Online (Sandbox Code Playgroud)

该指令中的问题是它仅在存在输入时检测,而不是在以编程方式更改值时检测.我使用重新形式,有时我用patchValue()函数设置值.我该怎么做才能触发更改功能?

angular-directive angular2-directives angular

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

使用模型驱动形式的禁用

我正在尝试使用disabled我的模型驱动形式.我有以下表格:

this.form = this.formBuilder.group({
    val1: ['', Validators.required],
    val2: [{value:'', disabled:this.form.controls.val1.valid}]
});
Run Code Online (Sandbox Code Playgroud)

我发现了一个错误(没有找到controlsthis.form可能是因为我使用)this.formthis.form.

我该如何解决这个问题?

PS我也尝试[disabled]='...'在我的html里面添加,但是我得到一个警告,说我应该使用formBuilder

angular2-forms angular2-formbuilder angular

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

从父级访问路由器出口组件

我有以下app root:

@Component({
    selector: 'my-app',
    providers: [],
    templateUrl: `<button (click)="callChildFunction()">Close</button>
                  <router-outlet></router-outlet>`
})
export class AppComponent {

    constructor() {

    }

    callChildFunction(){
        // Call myFunction() here
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的孩子(使用的组件router-outlet):

@Component({
    selector: 'child',
    providers: [],
    templateUrl: `<div>Hello World</div>`
})
export class ChildComponent {

    constructor() {

    }

    myFunction(){
        console.log('success');
    }

}
Run Code Online (Sandbox Code Playgroud)

我发现我可以使用RouterOutlet来获取组件函数,但似乎无法从应用程序根目录中访问它.

如何myFunction()从应用程序根调用?

angular angular-router

18
推荐指数
2
解决办法
7425
查看次数

将日期分配给ngbDatepicker的简短方法

我在我的Angular 2 webapp中使用了反应形式,我遇到了将日期分配给ngbDatepicker(ngbootstrap 1 alpha 6)的麻烦.我的对象有一个日期对象,例如:

var myObject = {date: new Date(1, 9, 2016)};
Run Code Online (Sandbox Code Playgroud)

在我的反应形式中,它配置如下:

input.form-control(name='date', ngbDatepicker, #date="ngbDatepicker", placeholder='jj.mm.aaaa', formControlName='date', type="text")
Run Code Online (Sandbox Code Playgroud)

我修补这样的形式:

this.form.patchValue({myObject: myObject});
Run Code Online (Sandbox Code Playgroud)

问题是ngbDatepicker采用以下结构的日期:

{day: DD, month: MM, year: YYYY}
Run Code Online (Sandbox Code Playgroud)

我找到了一个解决方法:

this.form.controls.myObject.controls.date.valueChanges
        .map((value) => {
            if(value) {
                if (typeof value.getMonth === 'function') {
                    this.form.controls.myObject.patchValue({
                        date: {
                            day: value.getUTCDay(),
                            month: value.getUTCMonth(),
                            year: value.getUTCFullYear()
                        }
                    });
                }
            }
            return value;
        })
        .subscribe((value) => {

        });
Run Code Online (Sandbox Code Playgroud)

一切都按预期工作(每当表单被修补时日期都会更新)但是它太冗长(18行代码)而且我的表单有十几个日期!

所以我的问题是,我可以通过更短的解决方案获得相同的结果吗?

ng-bootstrap angular

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

我是否需要发布复制的NSObjects - Objective-c

我想知道我是否需要发布复制的NSObject?例如,我只创建一个复制到数组中的字典:

码:

for (int num = 0; num < [object count]; num++) {
    [dictionary setObject:[object objectAtIndex:num] forKey:@"x"];
    [array addObject:[dictionary copy]];
}
Run Code Online (Sandbox Code Playgroud)

我必须发布字典吗?如果是,何时?

谢谢

iphone cocoa memory-management copy objective-c

14
推荐指数
2
解决办法
3952
查看次数

对核心数据实体的NSSets进行排序 - Objective-c

我想对核心数据NSSet的数据进行排序(我知道我们只能用数组做,但让我解释一下......).我有一个实体用户与实体配方有很多关系.配方具有属性名称和ID.我想得到这样的数据:

NSArray *id = [[user.recipes valueForKey:@"identity"] allObjects];
NSArray *name = [[user.recipes valueForKey:@"name"] allObjects];
Run Code Online (Sandbox Code Playgroud)

如果我在两个数组中的索引1处获取对象,它们对应于相同的配方...

谢谢

database sorting iphone core-data objective-c

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

强制启用通过引导CSS查看只读输入

我有一个使用bootstrap.css进行设计的应用程序.我有一个readonly输入看起来像因为bootstrap而禁用(光标不允许,背景颜色为灰色等...).我想通过readonly激活看起来启用输入.

我怎样才能做到这一点?

编辑(添加更多代码):

标题:

doctype html
html(ng-app='myApp')
  head
    title=title
    link(rel='stylesheet' href='stylesheets/bootstrap.min-3.1.1.css')
    link(rel='stylesheet' href='stylesheets/style.css')
Run Code Online (Sandbox Code Playgroud)

我的意见: input.form-control(readonly, placeholder='jj-mm-aaaa')

我的手写笔(style.css):

input[readonly]
  background-color: #fff
Run Code Online (Sandbox Code Playgroud)

html css html5 twitter-bootstrap

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

$ watch指令中的元素宽度

我正在尝试$watch在指令中使用元素的宽度:

appDrct.directive('setWidth', function($interval) {
    return {
        require: '?ngModel',
        link: function($scope, $elm, attr, ngModel) {

            $scope.$watch($elm.parent().width(), function() {
                console.log('Width changed');
            });
        }
     }
})
Run Code Online (Sandbox Code Playgroud)

但它不起作用......我知道我的宽度发生了变化(我尝试$interval显示宽度并改变)

javascript angularjs angularjs-directive

12
推荐指数
1
解决办法
3727
查看次数