我正在使用Angular2-rc4和angular-cli webpack,并希望实现chart.js库.
我使用以下方法将chart.js安装到我的项目中:
npm install chart.js --save
然后我尝试在我的组件中导入chart.js:
import {Component, OnInit, ViewChild} from '@angular/core';
import 'chart.js/src/chart.js';
declare let Chart;
@Component({
selector: 'app-dashboard',
templateUrl: 'dashboard.component.html',
styleUrls: ['dashboard.component.scss']
})
export class DashboardComponent {
chart: Chart;
}
Run Code Online (Sandbox Code Playgroud)
但我在控制台日志中出错:
[default] /Applications/MAMP/htdocs/bridge/src/app/dashboard/dashboard.component.ts:12:9
Cannot find name 'Chart'.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我已经将angular-cli与节点v6.5.0和npm v3.10.3安装到我的vagrant(Scotch)盒子中.运行'ng serve --port 4201'之后,我可以看到构建成功并且应用程序现在在http:// localhost:4201 /上提供服务
但是我不能只使用上面的地址,因为我在VM上运行.我试图将'127.0.0.1:4201'添加到主机上的hosts文件中,但无法正常工作.
谢谢
我正在构建动态表单,并且想要"动态"添加表单组.
这是我的代码几乎可以工作:
import {Component, OnInit} from '@angular/core';
import {FormGroup, FormBuilder, FormArray, Validators, FormControl} from "@angular/forms";
export class CombinedComponent implements OnInit {
ltsForm: FormGroup;
constructor(private formBuilder: FormBuilder) {
}
ngOnInit() {
this.ltsForm = this.initFormGroup();
// init products
for (let i = 0; i < 3; i++) { // add dynamically products
this.addProduct();
}
console.log(this.ltsForm); // Array 'prods' is empty
}
// initialize form group, but don't add products yet because they will be added dynamically later
initFormGroup() {
let group = …
Run Code Online (Sandbox Code Playgroud) 我正在使用User实体内部的回调进行自定义验证.
因此,我需要获取当前登录用户的User对象.
在控制器中,我可以这样做:
$user= $this->get('security.context')->getToken()->getUser();
Run Code Online (Sandbox Code Playgroud)
但是我应该如何在User实体中执行此操作?
我正在尝试使用websockets将一些数据从php应用程序发送到用户的浏览器.因此我决定将Swoole与RabbitMQ结合使用.
这是我第一次使用websockets并在阅读了一些关于Socket.IO,Ratchet等的帖子后,我决定停止使用Swoole,因为它是用C编写的,并且可以方便地与php一起使用.
这就是我理解使用websockets启用数据传输的想法:1)在CLI中启动RabbitMQ worker和Swoole服务器2)php应用程序向RabbitMQ发送数据3)RabbitMQ向worker发送带有数据的消息4)Worker接收带有数据的消息+建立与Swoole套接字服务器的套接字连接.5)Swoole服务器向所有连接广播数据
问题是如何将Swoole套接字服务器与RabbitMQ绑定?或者如何让RabbitMQ与Swoole建立连接并向其发送数据?
这是代码:
Swoole服务器(swoole_sever.php)
$server = new \swoole_websocket_server("0.0.0.0", 2345, SWOOLE_BASE);
$server->on('open', function(\Swoole\Websocket\Server $server, $req)
{
echo "connection open: {$req->fd}\n";
});
$server->on('message', function($server, \Swoole\Websocket\Frame $frame)
{
echo "received message: {$frame->data}\n";
$server->push($frame->fd, json_encode(["hello", "world"]));
});
$server->on('close', function($server, $fd)
{
echo "connection close: {$fd}\n";
});
$server->start();
Run Code Online (Sandbox Code Playgroud)
工作者从RabbitMQ接收消息,然后连接到Swoole并通过套接字连接(worker.php)广播消息
$connection = new AMQPStreamConnection('0.0.0.0', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('task_queue', false, true, false, false);
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
$callback = function($msg){
echo " …
Run Code Online (Sandbox Code Playgroud) 我在Angular-cli的Angular 2决赛中使用了observable.
package.json中的依赖项:
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"bootstrap-sass": "^3.3.7",
"chart.js": "^2.2.2",
"core-js": "^2.4.1",
"d3": "^4.2.3",
"d3-tip": "^0.7.1",
"ionicons": "^3.0.0",
"moment": "^2.15.1",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23"
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序在Safari 9.1.2以外的每个浏览器中都能正常工作 - 它会将此错误消息抛出到控制台:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:4200/Observable.js.map
Run Code Online (Sandbox Code Playgroud)
我试图在angular_cli.json中导入Rxjs:
"scripts": [
"../node_modules/rxjs/Rx.js"
],
Run Code Online (Sandbox Code Playgroud)
另外,我试图将rxjs导入到app.module.ts和这样的工作组件:
import {Observable} from 'rxjs/Rx';
Run Code Online (Sandbox Code Playgroud)
但是继续得到同样的错误.
难道我做错了什么?很奇怪只有Safari遇到这个错误.
我在清单实体中有一个ManyToMany关系:
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\ListingRepository")
* @ORM\Table(name="listings")
*/
class Listing extends MainEntity
{
/**
* @ORM\Id
* @ORM\Column(type="uuid")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\AttributeDescription", inversedBy="listings", cascade={"persist", "remove"})
* @JoinTable(name="listing_attriubute_descriptions",
* joinColumns={@JoinColumn(name="listing_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="attribute_description_id", referencedColumnName="id")}
* )
*/
public $attributeDescriptions;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->attributeDescriptions = new ArrayCollection();
}
public function removeAttributeDescription(AttributeDescription $attributeDescription)
{
if(!$this->attributeDescriptions->contains($attributeDescription))
{
return;
}
$this->attributeDescriptions->remove($attributeDescription);
return $this;
}
}
Run Code Online (Sandbox Code Playgroud)
在ListingService的某个地方,我试图从Listing实体中删除AttributeDescription,如下所示:
$listing->removeAttributeDescription($toRemoveAttributeDescription);
Run Code Online (Sandbox Code Playgroud)
但出现错误:警告:isset中的偏移量类型非法或为空
使用xdebug,我进入了ArrayCollection中的remove()方法:
public function remove($key)
{
if ( ! isset($this->elements[$key]) && ! array_key_exists($key, …
Run Code Online (Sandbox Code Playgroud) 如何在成功授权后返回json对象而不是重定向到默认路径?我正在使用Symfony 3.0.1,我不使用FOSBundle.
我的登录控制器如下所示:
class ClientLoginController extends Controller
{
/**
* @Route("/login", name="login")
*/
public function loginAction(Request $request)
{
$client = new Client();
$form = $this->createForm(ClientLoginType::class, $client);
$form->handleRequest($request);
$authenticationUtils = $this->get('security.authentication_utils');
$lastEmail = $authenticationUtils->getLastUsername();
$error = $authenticationUtils->getLastAuthenticationError();
if ($form->isSubmitted() && $form->isValid())
{
return new JsonResponse(
array(
'message' => 'Success! You're authorised!',
'result' => $this->renderView('SymfonyBundle::client/success.html.twig')
), 200);
}
return $this->render(
'SymfonyBundle::security/security.html.twig',
array(
'login_form' => $form->createView(),
'error' => $error,
'last_email' => $lastEmail,
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
而security.yml配置中的登录部分如下所示:
form_login:
login_path: login
check_path: login
username_parameter: …
Run Code Online (Sandbox Code Playgroud) angular ×4
php ×3
symfony ×3
angular-cli ×2
chart.js ×1
doctrine ×1
doctrine-orm ×1
javascript ×1
rabbitmq ×1
rxjs5 ×1
sockets ×1
swoole ×1
validation ×1
websocket ×1