本文整理汇总了TypeScript中app/services.UserService类的典型用法代码示例。如果您正苦于以下问题:TypeScript UserService类的具体用法?TypeScript UserService怎么用?TypeScript UserService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserService类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('UserService', () => {
var userService:UserService;
var backend:MockBackend;
beforeEachProviders(() => [APP_TEST_PROVIDERS]);
beforeEach(inject([UserService, MockBackend], (..._) => {
[userService, backend] = _;
}));
afterEach(() => localStorage.clear());
describe('.list', () => {
it("list users", (done) => {
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(dummyListJson),
})));
expect(conn.request.method).toEqual(RequestMethod.Get);
expect(conn.request.url).toEqual('/api/users?page=1&size=5');
});
userService.list().subscribe(res => {
expect(res).toEqual(dummyListJson);
done();
});
});
}); // .list
describe('.get', () => {
it("get user", (done) => {
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(dummyGetJson),
})));
expect(conn.request.method).toEqual(RequestMethod.Get);
expect(conn.request.url).toEqual('/api/users/1');
});
userService.get(1).subscribe(res => {
expect(res).toEqual(dummyGetJson);
done();
});
});
}); // .get
describe('.create', () => {
it("create user", (done) => {
const params:UserParams = {
email: 'test1@test.com',
password: 'secret',
name: 'test1',
};
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new BaseResponseOptions()));
expect(conn.request.method).toEqual(RequestMethod.Post);
expect(conn.request.url).toEqual('/api/users');
expect(conn.request.text()).toEqual(JSON.stringify(params));
});
userService.create(params).subscribe(() => {
done();
});
});
}); // .create
describe('.updateMe', () => {
it("update me", (done) => {
const params:UserParams = {
email: 'test1@test.com',
password: 'secret',
name: 'test1',
};
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new BaseResponseOptions()));
expect(conn.request.method).toEqual(RequestMethod.Patch);
expect(conn.request.url).toEqual('/api/users/me');
expect(conn.request.text()).toEqual(JSON.stringify(params));
});
userService.updateMe(params).subscribe(() => {
done();
});
});
}); // .updateMe
describe('.listFollowings', () => {
it("list followings", (done) => {
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(dummyListJson),
})));
expect(conn.request.method).toEqual(RequestMethod.Get);
expect(conn.request.url).toEqual('/api/users/1/followings?maxId=2&count=3');
});
userService.listFollowings('1', {maxId: 2, count: 3}).subscribe(res => {
expect(res).toEqual(dummyListJson);
done();
});
});
}); // .listFollowings
describe('.listFollowers', () => {
it("list followers", (done) => {
backend.connections.subscribe(conn => {
//.........这里部分代码省略.........
示例2: list
list(page) {
this.userService.list({page: page, size: 5})
.subscribe(usersPage => {
this.users = usersPage.content;
this.totalPages = usersPage.totalPages;
}, e => this.errorHandler.handle(e))
;
}
示例3: onSubmit
onSubmit(params) {
this.userService.create(params)
.mergeMap(() => {
return this.loginService.login(params.email, params.password);
})
.subscribe(() => {
this.router.navigate(['/Home']);
}, this.handleError)
;
}
示例4: it
it("get user", (done) => {
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(dummyGetJson),
})));
expect(conn.request.method).toEqual(RequestMethod.Get);
expect(conn.request.url).toEqual('/api/users/1');
});
userService.get(1).subscribe(res => {
expect(res).toEqual(dummyGetJson);
done();
});
});
示例5:
this.listProvider = (params) => {
return userService.listFollowers(this.userId, params);
};