我在尝试运行"vagrant up"终端命令时遇到此错误:
本机的配置存在错误.请修正以下错误,然后重试:
*必须指定一个方框.
在我的Homestead/.vagrant/machines/default/virtualbox文件夹中,那里没有文件,所以我假设它是指它必须指定一个盒子的时候,但是我不知道如何包含一个盒子,因为这是我第一次使用vagrant,我没有决心在网上搜索.
有人有解决方案吗?
编辑(Vagrantfile):
require 'json'
require 'yaml'
VAGRANTFILE_API_VERSION = "2"
confDir = $confDir ||= File.expand_path("~/.homestead")
homesteadYamlPath = confDir + "/Homestead.yaml"
homesteadJsonPath = confDir + "/Homestead.json"
afterScriptPath = confDir + "/after.sh"
aliasesPath = confDir + "/aliases"
require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb')
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if File.exists? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
end
if File.exists? homesteadYamlPath then
Homestead.configure(config, YAML::load(File.read(homesteadYamlPath)))
elsif File.exists? homesteadJsonPath then
Homestead.configure(config, JSON.parse(File.read(homesteadJsonPath)))
end
if File.exists? afterScriptPath then
config.vm.provision "shell", path: afterScriptPath …Run Code Online (Sandbox Code Playgroud) 我刚刚在Django网站上按照本教程安装了Python和Django ,而且这一部分的一切工作都很好并且没有产生任何错误.
现在我在"开发服务器"部分,并python manage.py runserver在我所在的项目目录中运行该命令manage.py,我收到此错误:
分段故障
没有其他的.
任何人都知道这里发生了什么以及如何解决这个问题?
如果它的事项,这是我的manage.py文件(django在from django.core.management ...行标记为我的IDE(PyCharm错误)和错误说Unresolved reference 'django'):
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "davilex.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个 goroutines 循环,该循环采用接收字符串的通道,并且每次接收到它时都应该将值附加到另一个字符串。只有在所有 goroutine 结束时(goroutine 计数应该是list传入的长度),代码才应该继续。
我下面的示例似乎没有将strReceiver通道中的值附加到 上str,因为 str 从未被修改过。
有谁知道怎么了?
func appendToStr(str string, list []string, origin *url.URL) {
var currProc int32 = 0;
var maxProc int32 = int32(len(list))
var strReceiver := make(chan string, len(list))
for _, item := range list {
go func() {
doAsyncAndIncrement(item, strReceiver, &currProc)
str += <-strReceiver
}()
}
for {
if atomic.LoadInt32(&currProc) <= maxProc {
break;
}
}
// continue on using 'str' which now contains the append values …Run Code Online (Sandbox Code Playgroud) 我已经配置了我的tsconfig.json所以我可以在我的代码中使用简短的导入路径以简化.例如,我可以做import { FooService } from 'core'而不是被迫做类似的事情import { FooService } from '../../../core/services/foo/foo.service'.
这工作得很好,除了某些原因我现在已经创建了一个新文件,其中一个导入错误:
找不到命名空间'环境'.
由于以下行发生此错误: import { environment } from 'environment';
这很奇怪,因为我在许多其他服务中都有相同的导入,并且没有一个抛出错误,它只发生在我创建的这个新文件中.
这是我的tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"paths": {
"core": ["app/core"],
"core/*": ["app/core/*"],
"shared": ["app/shared"],
"shared/*": ["app/shared/*"],
"modal": ["app/modal"],
"modal/*": ["app/modal/*"],
"environment": ["environment/environment"]// HERE
},
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个执行昂贵的同步任务的函数。在我的情况下,它是通过 pdfkit 生成的客户端 pdf,但让我们用 while-loop sleep 来模拟它。
我想在运行任务之前显示一个“加载”微调器,并在完成后隐藏它。
如果一切都同步运行,Angular 将没有机会在一切结束之前运行更改检测循环,所以我想我只需要找到一种方法来异步运行它。
我试着把它包装在一个承诺中,所以假设我有:
sleep(ms) {
return new Promise((resolve, reject) => {
const expire = (new Date()).getTime() + ms;
while ((new Date()).getTime() < expire);
resolve();
});
}
Run Code Online (Sandbox Code Playgroud)
但是我是否使用 .then() 调用运行它:
run() {
this.running = true;
this.sleep(2000).then(() => {
this.running = false;
});
}
Run Code Online (Sandbox Code Playgroud)
或使用异步/等待:
async run() {
this.running = true;
await this.sleep(2000);
this.running = false;
}
Run Code Online (Sandbox Code Playgroud)
在函数结束之前不会检测到更改,并且不会显示任何内容。
我想问题是 Javascript 仍然是单线程的,并且 promise 在创建时仍然会立即运行,所以一切基本上仍然是同步运行的。
但即使使用 ChangeDetectorRef.detectChanges() 强制更改检测也无济于事。
到目前为止,我发现的唯一解决方案是在 setTimeout hack 中运行它:
setTimeoutRun() {
this.running = …Run Code Online (Sandbox Code Playgroud) event-loop synchronous promise angular angular-changedetection
我知道这是一个构造不良的问题,但我不知道怎么回答它.
我是AngularJS的新手,我试图基本上说"如果用户点击"这个"个人资料",请转到/models/{{ model.id }}model.id是被点击的"此"个人资料的价值.
基本上,main.html只有一些信息(如果你愿意,只有一个片段),当点击一个配置文件时,它应该转到/models/{{ model.id }}然后显示完整的配置文件,而不仅仅是一个片段.
到目前为止我的工作原理是,当悬停配置文件链接时它会显示正确的ID,并使用正确的url参数进入正确的视图,但是如何在视图中写入数据,以便数据将会出现与点击的ID相关?我通常用PHP/Laravel和MySQL来做这个,但我想用Angular来试试.
app.js:
'use strict';
angular
.module('swoleincApp', [
'ngRoute',
'ngSanitize',
'ngAnimate'
])
.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$routeProvider
.when('/models', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/models/:id', {
templateUrl: 'views/individual.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/models'
});
$locationProvider.html5Mode(true);
}]);
Run Code Online (Sandbox Code Playgroud)
MainCtrl.js:
'use strict';
angular
.module('swoleincApp')
.controller('MainCtrl', ['$scope', '$http', MainCtrl]);
function MainCtrl($scope, $http) {
$http.get('storage/models.json').success(function(data) {
$scope.models = data;
});
}
Run Code Online (Sandbox Code Playgroud)
main.html中:
<div class="model-container" ng-repeat="model in models">
<a href="/models/{{ model.id }}">
<div class="row"> …Run Code Online (Sandbox Code Playgroud) 我想创建一个可重用的组件,该组件可以采用自定义模板来呈现数据,同时可以组成业务逻辑,因此我不必重复自己的工作。
用例示例:分页列表。分页逻辑应位于可重用组件中,因此只能编写一次,但是数据的主题/表示应使用进行自定义ng-template。
我ngTemplateOutlet在子组件ng-template中使用了父项中的引用,但出现此错误:
错误TypeError:templateRef.createEmbeddedView不是函数
首先ng-container在可重复使用的组件工作正常,那就是是给错误的最后3。
这是我的可重用组件:
@Component({
selector: 'reuseable-component',
...
})
export class ChildComponent {
@ContentChild(TemplateRef) templateRef;
}
<ng-container *ngIf="...">
<ng-template [ngTemplateOutlet]="templateRef"
[ngTemplateOutletContext]="{$implicit: result}">
</ng-template>
</ng-container>
<ng-container *ngIf="..." [ngTemplateOutlet]="loading"></ng-container>
<ng-container *ngIf="..." [ngTemplateOutlet]="loadingMore"></ng-container>
<ng-container *ngIf="..." [ngTemplateOutlet]="noResults"></ng-container>
Run Code Online (Sandbox Code Playgroud)
这是用法:
<reuseable-component>
<ng-template let-result>
// I have access to 'result' variable here, works fine.
</ng-template>
<ng-template #loading>
// This gives the error above
</ng-template>
<ng-template #loadingMore>
// This gives the error above
</ng-template>
<ng-template #noResults>
// …Run Code Online (Sandbox Code Playgroud) 这是一个愚蠢的问题,我已经四处寻找类似的答案并找到了一些,但是它们比我要的更具体.
假设我想要包含一个自定义styles.css或scripts.js文件,我只是在resources/views文件夹中创建一个css/js文件夹,然后在我的blade.php文件中调用它们,就像我在不使用Laravel时通常在HTML文件中那样做?
例: <link type="text/css" rel="stylesheet" href="css/styles.css">
或者Laravel有不同的方法吗?
我对构建应用程序的方式感到好奇(我可能在无关紧要的事情上浪费了时间),但好奇心仍然让我发问。
在 AngularJS 中,应用程序如何工作?例如,如果我在 app.js 中有此代码(删除了我的实现,仅显示结构):
(function() {
'use strict';
angular
.module('app', ['ui.router', 'satellizer', 'permission', 'angular-jwt', 'ui.bootstrap', 'angular-loading-bar'])
.config(['$stateProvider', '$urlRouterProvider', '$authProvider', '$locationProvider', '$httpProvider', Config])
.run(['$rootScope', '$state', '$auth', 'jwtHelper', 'Permission', Run]);
function Run($rootScope, $state, $auth, jwtHelper, userService, Permission) {
// Some code
}
function Config($stateProvider, $urlRouterProvider, $authProvider, $locationProvider, $httpProvider) {
// Some code
}
})();
Run Code Online (Sandbox Code Playgroud)
..什么先运行?我很好奇,因为我想知道我是否应该放在run之前config,等等。我不想加载配置,而是等待run做某事,而run先加载会更有效率,所以无需等待......如果这甚至是一个问题的话。
任何澄清将不胜感激。
我对我的 CSP 标头遵循Google 的严格 CSP 政策,并且我正在正确添加随机数,但是我的脚本在浏览器中不断收到此错误:
拒绝加载脚本 ' http://localhost:8080/client/dist/inline.6e0c61259742e86be1dd.bundle.js ' 因为它违反了以下内容安全策略指令:“script-src nonce-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFxhxKQFDaFpLSEFWJFunc' -eval' '严格动态' https: http:"。存在“strict-dynamic”,因此禁用了基于主机的白名单。
如您所见,随机数与脚本中的随机数匹配:
<script type="text/javascript" src="/client/dist/inline.6e0c61259742e86be1dd.bundle.js" nonce="XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLSjFbcXoEFfRsWxP"></script>
Run Code Online (Sandbox Code Playgroud)
这是我用于script-src. "%s" 表示随机生成的随机数,它将在响应设置标头之前进行插值:
script-src nonce-%s 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
angular ×3
angularjs ×2
javascript ×2
laravel ×2
typescript ×2
browser ×1
django ×1
event-loop ×1
go ×1
homestead ×1
http ×1
http-headers ×1
json ×1
laravel-5 ×1
php ×1
promise ×1
python ×1
router ×1
security ×1
synchronous ×1
terminal ×1
vagrant ×1
virtualbox ×1