我有以下模块声明:
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) 我正在尝试在学习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)