当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript services.UserService类代码示例

本文整理汇总了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 => {
//.........这里部分代码省略.........
开发者ID:windwang,项目名称:angular2-app,代码行数:101,代码来源:UserService.spec.ts

示例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))
   ;
 }
开发者ID:ishara,项目名称:angular2-app,代码行数:8,代码来源:UserListPage.ts

示例3: onSubmit

 onSubmit(params) {
   this.userService.create(params)
     .mergeMap(() => {
       return this.loginService.login(params.email, params.password);
     })
     .subscribe(() => {
       this.router.navigate(['/Home']);
     }, this.handleError)
   ;
 }
开发者ID:gtostock,项目名称:angular2-app,代码行数:10,代码来源:SignupPage.ts

示例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();
   });
 });
开发者ID:windwang,项目名称:angular2-app,代码行数:13,代码来源:UserService.spec.ts

示例5:

 this.listProvider = (params) => {
   return userService.listFollowers(this.userId, params);
 };
开发者ID:mauricio1990silva,项目名称:angular2-app,代码行数:3,代码来源:FollowerListPage.ts


注:本文中的app/services.UserService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。