小编juf*_*qui的帖子

从 Angular 2+ 模块声明中的导出函数访问服务

我有以下模块声明:

import { ConnectionService } from './services/connection.service';
import { NgModule } from '@angular/core';
import { Http, RequestOptions } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';

export function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig({
    tokenName: 'token',
    tokenGetter: (() => sessionStorage.getItem('token'))
  }), http, options);
}

@NgModule({
  providers: [
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [Http, RequestOptions]
    }
  ],
})

export class AuthModule { }
Run Code Online (Sandbox Code Playgroud)

和服务:

import { Injectable } from '@angular/core';

@Injectable()
export class ConnectionService {
    id; …
Run Code Online (Sandbox Code Playgroud)

service injectable typescript angular

5
推荐指数
1
解决办法
4924
查看次数

塞特不在模特工作

我正在尝试在学习Go时尝试理解MVC架构,并且我试图从控制器中更改模型中的值.

代码现在创建一个只保存字符串的模型,视图显示终端上的字符串,但控制器无法更改它(它获得用户输入没有任何问题).

现在我在终端上的文字是这样的:

Hello World!
asdf //my input
Hello World!
Run Code Online (Sandbox Code Playgroud)

我想得到的输出将是这样的:

Hello World!
asdf //my input
asdf
Run Code Online (Sandbox Code Playgroud)

这是我的文件:

model.go

package models

type IndexModel struct {
    Text string
}

func (m *IndexModel) InitModel() string {
    return m.Text
}

func (m *IndexModel) SetText(newText string) {
    m.Text = newText
}
Run Code Online (Sandbox Code Playgroud)

view.go

package views

import "github.com/jufracaqui/mvc_template/app/models"

type IndexView struct {
    Model    models.IndexModel
}

func (v IndexView) Output() string {
    return v.Model.Text
}
Run Code Online (Sandbox Code Playgroud)

controller.go

package controllers

import "github.com/jufracaqui/mvc_template/app/models"

type IndexController struct {
    Model models.IndexModel
} …
Run Code Online (Sandbox Code Playgroud)

setter go

0
推荐指数
1
解决办法
73
查看次数

标签 统计

angular ×1

go ×1

injectable ×1

service ×1

setter ×1

typescript ×1