我是angular2的新手.我想将文本区域中的用户输入存储在组件中的变量中,以便我可以将一些逻辑应用于此输入.我试过ngModel
但它不起作用.我的textarea代码:
<textarea cols="30" rows="4" [(ngModel)] = "str"></textarea>
Run Code Online (Sandbox Code Playgroud)
在我的组件内:
str: string;
//some logic on str
Run Code Online (Sandbox Code Playgroud)
但str
我的组件内部没有任何价值.我使用的方式有错误ngModule
吗?
我想从日期选择器获取最小和最大日期,但最小日期应为当前日期的" - 18",最大日期应为当前日期的" - 100".
假设当前年份是2018年,那么我想要最小日期2000和最大日期1918.
到目前为止我所做的是:
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorian components:NSYearCalendarUnit fromDate:[NSDate date]];
NSInteger year = [components year];
int mindt = year - 18;
int maxdt = year -100;
// NSDate * MinDate = [components year] - 18;
// NSDate * MaxDate = [components year] - 100;
// self.datePicker.minimumDate = MinDate;
// self.datePicker.maximumDate = MaxDate;
Run Code Online (Sandbox Code Playgroud)
但我不能得到这个整数到我的日期格式..
我需要检查我的应用程序何时启动,如果它正在更新,因为我需要创建一个视图,只有在应用程序首次安装后才会出现,以便在更新后再次显示.
在我的角度应用程序中,我有3个输入说 - 代码,名称和价格.并且有一个表格显示用户选择.
当我点击添加按钮时,下拉列表中的选择应该填充到表格中,
Product Price Action
124578-ABC 100 <Delete Button>
Run Code Online (Sandbox Code Playgroud)
当我单击删除按钮时,相应的行应该被删除.我尝试使用jquery这样做.但我想知道做角色的方式.
我已经为我的应用程序完成了基本通知.我想在我的通知中添加声音效果.
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
return;
localNotification.fireDate = [NSDate date];
//localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = msg;
localNotification.soundName = @"Morse.aiff";
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
Run Code Online (Sandbox Code Playgroud)
如何添加音效?
我刚刚开始在iOS上使用Realm.io并尝试填充对象,但我得到以下内容:
Invalid value nil for property
如何使属性可选?
有没有办法将应用程序发送到后台?与您可以调用的方式类似XCUIApplication.terminate()
,我有一些要测试的UI元素applicationDidBecomeActive(_:)
.有谁知道这是否可能?
我已经设置了一个触发NgbPopover
悬停的元素:
<a [ngbPopover]="popContent" popoverTitle="MyPopover" triggers="mouseenter:mouseleave">Hover me</a>
Run Code Online (Sandbox Code Playgroud)
目前,当悬停元素时将显示弹出窗口,并在离开该区域时连续解除.我想要实现的是当用户将其悬停时保持弹出窗口打开,并且仅当用户离开元素或弹出窗口时才将其关闭.
我正在使用HTTP Patch请求更新一组实体到远程后端.来自后端的响应仅包括更新的实体(即,不是所有实体).
我使用实体状态适配器设置我的reducer并用于updateMany
更新我的实体:
case settings.SettingsActionTypes.UpdateSettingsSuccess: {
return {
...state,
...adapter.updateMany(action.payload.map((category) => Object.assign({}, {id: category.name, changes: category})), state),
loaded: true,
loading: false,
}
}
Run Code Online (Sandbox Code Playgroud)
虽然这会更新接收更新的实体,但它会删除后端未返回的所有其他实体.
有没有办法告诉ngrx只更新包含在action.payload
?中的实体?
我想对服务进行单元测试,但是,在运行测试时,我收到以下错误:
未捕获(在promise中)SyntaxError:MapSubscriber.Array中MapSubscriber.Array.concat.MapSubscriber._next(map.js:77)位于MapSubscriber.project(auth.service.ts:217)的位置1的JSON中的意外标记o. concat.Subscriber.next(Subscriber.js:89)在TakeSubscriber.Array.concat.TakeSubscriber._next(take.js:80),位于ReplaySubject.Array的TakeSubscriber.Array.concat.Subscriber.next(Subscriber.js:89) ReplaySubject上的ReplaySubject.Array.concat.Orray.Array.concat.Atry.Subject.Array.concat.Atry.Subject._trySubscribe(Subject.js:97)中的ReplaySubject.Array.concat.Observable._trySubscribe(Observable.js:57).concat.ReplaySubject._subscribe(ReplaySubject.js:55).位于MapOperator的AnonymousSubject.Array.concat.Observable.subscribe(Observable.js:42)的TakeOperator.Array.concat.TakeOperator.call(take.js:60)中的Array.concat.Observable.subscribe(Observable.js:45) .Array.concat.MapOperator.call(map.js:54)位于CatchOperator.Array.concat.CatchOperator.call(catch.js:79)的AnonymousSubject.Array.concat.Observable.subscribe(Observable.js:42)一个 nonymousSubject.Array.concat.Observable.subscribe(Observable.js:42)
相应的行(auth.service.ts:217
)在代码中突出显示.运行应用程序完全正常,因此我没有看到测试失败的明显原因.
注意:这个SO帖子表明我正在解析对象两次.但是,当运行应用程序时,它不应该失败吗?
auth.service.ts
public login(username: string, password: string): Observable<User> {
// ...
return this.http.request(path, requestOptions).map((response: Response) => {
if (response.status === 200) {
const token = response.json().token; // <<-- Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1
const user = this.extractUser(response);
return user;
}
return null;
})
.catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)
auth.service.spec.ts
describe('AuthService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
AuthService,
MockBackend,
BaseRequestOptions,
{
provide: Http, …
Run Code Online (Sandbox Code Playgroud) angular ×5
ios ×5
objective-c ×2
swift ×2
data-binding ×1
json ×1
mocking ×1
ng-bootstrap ×1
ngrx ×1
ngrx-entity ×1
nsdate ×1
nsdatepicker ×1
realm ×1
textarea ×1
unit-testing ×1