當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。