我刚刚在现有项目上尝试了Go 1.18 工作区。考虑以下项目目录结构:
project-root/
|-- app/
| |-- go.mod
| |-- go.sum
Run Code Online (Sandbox Code Playgroud)
根据文档go work init ./app,我在项目的根目录中运行了该命令。该命令go.work按预期创建了一个文件,但也创建了一个go.work.sum非预期的文件。
令人困惑的是,go.work.sum引用了两个可以在 中找到的模块,但是在和 之间go.sum进行比较时,每个模块的版本并不相同。那么还有一个问题,为什么只引用了这两个模块,而没有引用其他模块呢?请注意,工作区中只有一个模块。go.sumgo.work.sumgo.work.sum
该文件跟踪什么go.work.sum?它在任何地方都有记录吗?
我有一个Angular CLI工作区,包含两个库项目,foo和bar.当我构建两个库中的第二个时foo,构建失败并出现以下错误:
错误TS6059:文件'/code/projects/bar/src/lib/types.ts'不在'rootDir''/ code/projects/foo/src'下.'rootDir'预计会包含所有源文件.
Run Code Online (Sandbox Code Playgroud)Error: error TS6059: File '/code/projects/bar/src/lib/types.ts' is not under 'rootDir' '/code/projects/foo/src'. 'rootDir' is expected to contain all source files. at Object.<anonymous> (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:53:68) at Generator.next (<anonymous>) at /code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:7:71 at new Promise (<anonymous>) at __awaiter (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:3:12) at Object.compileSourceFiles (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:19:12) at Object.<anonymous> (/code/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:26:32) at Generator.next (<anonymous>) at /code/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:7:71 at new Promise (<anonymous>)
我已复制了错误的沙箱回购GitHub上这里.我仍然遇到错误,尽可能地简化了代码.您可以通过npm run build在rootDir-expect-all-source-files-error分支上执行来重现错误.错误的原因是什么?可能这是一个或与ng-packagr或的错误?或者只是一个配置问题?ngctsc
下面是我可以进行构建传递的代码更改,但我想知道导致错误的原因是什么.
export class BarComponent …Run Code Online (Sandbox Code Playgroud) 这个问题的角度版本这个问题.
以下代码摘要总结了我的第一次尝试:
class NewParentComponent {
constructor(elRef: ElementRef) {
elRef.nativeElement.appendChild(myMovableElement);
// where the reference to myMovableElement may come from a service.
}
}
Run Code Online (Sandbox Code Playgroud)
此尝试带有以下问题:
Renderer某种方式实现?(Ans:Per cgTag的回答,使用Renderer2).ngOnDestroy上调用该方法.看到这个Plunker演示了这个问题.此Plunker构建在Angular Dynamic Component Loader示例之上.打开浏览器控制台日志并注意"已销毁!" 每次广告横幅更改时都会记录文字,即使是"拖我!" 文本被拖入下拉框.
我正在寻找将单页 Angular 应用程序转换为旧式 html-css-javascript 静态文件的方法,该文件在我的电脑上运行,无需任何复杂node.js或任何设置npm
我一直在寻找并找到的Angular是,我一直在寻找Bootstrap-sidebar轻量级的css,js但我能找到的所有示例都有很大很大的 Javascript 文件,所以我看到 Angular 有一些新的 Sidebar 实现。
我想在侧边栏角(角应用程序),以旧风格转换HTML,css以及js文件,这样我可以在没有任何复杂的节点服务器运行它们。
有什么方法可以从 Angular 应用程序中获取 javascript、css 和 html。我听说过WebPack但没有尝试过,所以任何建议将不胜感激。
如果上述过程可以在React建议我一个可靠的方法来做到这一点。
编辑:我想要的是,我想访问该文件,因为file://path/to/index.html我不想要 HTTP ( http://localhost/index.html)
我正在使用 Go 来处理类型参数(泛型)1.18beta1。
考虑以下片段:
package main
import (
"fmt"
)
func main() {
foo := &Foo[string, int]{
valueA: "i am a string",
valueB: 123,
}
fmt.Println(foo)
}
type Foo[T1 any, T2 any] struct {
valueA T1
valueB T2
}
func (f *Foo[_,_]) String() string {
return fmt.Sprintf("%v %v", f.valueA, f.valueB)
}
Run Code Online (Sandbox Code Playgroud)
此代码片段无法构建,并出现以下错误:
<autogenerated>:1: cannot use .this (type *Foo[string,int]) as type *Foo[go.shape.string_0,go.shape.string_0] in argument to (*Foo[go.shape.string_0,go.shape.int_1]).String
Run Code Online (Sandbox Code Playgroud)
_由于类型参数提案中的以下语句,我尝试在方法声明中使用:
方法声明中列出的类型参数不必与类型声明中的类型参数具有相同的名称。特别是,如果方法不使用它们,则它们可以是 _。
上面的构建错误是错误1.18beta1还是我遗漏了什么?
我是Go的新手,我想了解为什么下面的代码片段无法编译.接受函数作为可能具有任何返回类型的函数参数的Go方式是什么?
package main
func main() {
test(a) // Error: cannot use a (type func() string) as type func() interface {} in argument to test
test(b) // Error: cannot use b (type func() int) as type func() interface {} in argument to test
}
func a() string {
return "hello"
}
func b() int {
return 1
}
func test(x func() interface{}) {
// some code...
v := x()
// some more code....
}
Run Code Online (Sandbox Code Playgroud)
播放:https://play.golang.org/p/CqbuEZGy12
我的解决方案基于Volker的答案:
package main …Run Code Online (Sandbox Code Playgroud) 考虑以下 Dockerfile:
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install -y apache2 && \
apt-get clean
ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]
Run Code Online (Sandbox Code Playgroud)
当使用命令运行容器时,容器将启动并保持运行状态,从而允许按预期从主机docker run -p 8080:80 <image-id>访问默认的 Apache 网页。https://localhost:8080但是,使用此运行命令,我无法使用 退出容器Ctrl+C,也如预期的那样,因为容器不是使用该-it选项启动的。现在,如果-it将选项添加到运行命令中,则容器在启动后立即退出。这是为什么?有没有一种优雅的方法可以让 apache 在退出时在前台运行Ctrl+C?
我创建了下面的 Observable 构造函数,它的工作原理与描述的一样。有谁知道使用 RxJs 附带的运算符是否有更简洁的方法来实现相同的行为?我正在查看接近所需行为的bufferToggle,但我需要在缓冲区关闭时传递发出的值。
函数说明:缓冲器所发射的source值,如果condition发射true,并穿过出射source如果值condition发射false。如果条件在 befalse之后发出true,则缓冲区按照接收到的顺序释放每个值。缓冲区被初始化为传递发出的source值,直到condition发出true.
function bufferIf<T>(condition: Observable<boolean>, source: Observable<T>): Observable<T> {
return new Observable<T>(subscriber => {
const subscriptions: Subscription[] = [];
const buffer = [];
let isBufferOpen = false;
subscriptions.push(
// handle source events
source.subscribe(value => {
// if buffer is open, or closed but buffer is still being
// emptied from …Run Code Online (Sandbox Code Playgroud) Angular CLI项目中是否有方法让库提供polyfill?在内部angular.json,主应用程序默认配置为"polyfills": "src/polyfills.ts".此选项不适用于库项目.
我的具体用例是我的库有一个需要polyfill的依赖项.如果库无法在应用程序中导入polyfill时自动提供polyfill,我需要记录并通知库用户自己添加polyfill.
APP_INITIALIZER在库模块中定义时,构建将失败并显示Lambda not supported错误.按照文档导出函数时抛出构建错误:
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { MylibComponent } from './mylib.component';
export function myLibInit() {
return () => console.log('Hi from exported function');
}
@NgModule({
providers: [
{
provide: APP_INITIALIZER,
multi: true,
useFactory: myLibInit
}
]
})
export class MylibModule { }
Run Code Online (Sandbox Code Playgroud)
构建误差均投掷dev和prod.
我也尝试使用ES6对象方法简写符号来定义工厂函数:
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { MylibComponent } from './mylib.component';
@NgModule({
providers: [
{
provide: APP_INITIALIZER,
multi: true,
useFactory() { …Run Code Online (Sandbox Code Playgroud) angular ×6
angular-cli ×3
go ×3
ng-packagr ×3
docker ×1
dockerfile ×1
generics ×1
go-modules ×1
go-work ×1
javascript ×1
reactivex ×1
rxjs ×1
typescript ×1