我在使用Angular2和SystemJS运行以下版本的JSPM时遇到以下问题(版本:Angular@2.0.0-alpha.27,JSPM @ 0.16.0-beta.2和SystemJS@0.18.0)曾经的打字稿是编译(没有错误)我在浏览器中收到以下错误:
/jspm_packages/npm/angular2@2.0.0-alpha.27/src/util/decorators.js:70 Uncaught reflect-metadata shim is required when using class decorators
Run Code Online (Sandbox Code Playgroud)
现在,当我手动包含文件Reflect.js:\ jspm_packages \npm\reflect-metadata@0.1.0\Reflect.js时,问题就消失了但是下一个问题出现了,说明列表在另一个角度文件中是未定义的.
从system.js和typescript/jspm.io看到下面的bitbucket src中的配置文件(src代码)
我想知道的是,如果它现在甚至可以使用jspm和system.js来检索角度正常运行所需的所有角度包.看作system.js的配置确实明确指出angular取决于它:
"npm:angular2@2.0.0-alpha.27": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.1",
"reflect-metadata": "npm:reflect-metadata@0.1.0",
"rx": "npm:rx@2.5.1",
"url": "github:jspm/nodelibs-url@0.1.0",
"zone.js": "npm:zone.js@0.5.1"
},
Run Code Online (Sandbox Code Playgroud)
但它们未被检索(查看网络选项卡)
我如何将一项服务注入另一项服务?例如,假设我有一个需要另一个Collection(TeamCollection => PlayerCollection)的Collection.目前我只创建两个单独的集合,并使用类似的东西:
import {PlayerCollection} from "<<folder>>/player";
Run Code Online (Sandbox Code Playgroud)
但是这需要我在Typescript中为我想要成为单例实例的每个服务编写自己的单例getInstance代码.
这样做的正确方法是什么?我希望在我的组件中拥有两个单例,并且能够使用构造函数语法将一个服务注入另一个服务,而无需创建单例的新实例.
class TeamCollection {
constructor(@Inject(PlayerCollection): PlayerCollection) {}
}
Run Code Online (Sandbox Code Playgroud) 我的问题似乎与这个问题相似:
但由于没有给出那个答案,我想知道是否有人能够/能够和我一起解决这个问题.我遇到的问题是我创建了一个可拖动的div并将其附加到一个可以排序的div中.当我指定任何这样的参数时:
$(el).sortable({ ... arguments ... });
Run Code Online (Sandbox Code Playgroud)
当元素被删除时会导致错误,如果留空,它会很奇怪地工作正常并且没有问题.该错误还会阻止可拖动元素触发任何函数.
Uncaught TypeError: Cannot read property 'options' of undefined
jquery-ui-1.10.3.custom.js:2204
$.ui.plugin.add.stop jquery-ui-1.10.3.custom.js:2204
$.extend.plugin.call jquery-ui-1.10.3.custom.js:284
$.widget._trigger jquery-ui-1.10.3.custom.js:2017
(anonymous function) jquery-ui-1.10.3.custom.js:401
$.widget._mouseStop jquery-ui-1.10.3.custom.js:1702
(anonymous function) jquery-ui-1.10.3.custom.js:401
$.widget._mouseUp jquery-ui-1.10.3.custom.js:957
(anonymous function) jquery-ui-1.10.3.custom.js:401
$.widget._mouseUp jquery-ui-1.10.3.custom.js:1721
(anonymous function) jquery-ui-1.10.3.custom.js:401
$.widget._mouseDown._mouseUpDelegate jquery-ui-1.10.3.custom.js:913
jQuery.event.dispatch jquery-1.10.2.js:5095
jQuery.event.add.elemData.handle jquery-1.10.2.js:4766
Run Code Online (Sandbox Code Playgroud)
这是出错的代码:
$.ui.plugin.add("draggable", "cursor", {
start: function() {
var t = $("body"), o = $(this).data("ui-draggable").options;
if (t.css("cursor")) {
o._cursor = t.css("cursor");
}
t.css("cursor", o.cursor);
},
stop: function() {
var o = $(this).data("ui-draggable").options;
if …Run Code Online (Sandbox Code Playgroud) javascript jquery jquery-ui jquery-ui-sortable jquery-ui-draggable
所以基于我之前的问题:Angular2"服务"如何将一个服务注入另一个服务(单例)
我现在有一个答案,一个新的问题在我身上恍然大悟.这是因为到目前为止我所看到的所有服务都包含在bootstrap方法中.Pascal Precht的博客文章也表明了这一点:http://blog.thoughtram.io/angular/2015/09/17/resolve-service-dependencies-in-angular-2.html
但对我而言,这与(实际上与Angular1相比)的编码非常难看.为了在这些实例中工作,我必须在app组件中包含我的所有服务(Angular1配置模块).虽然强度应该来自让每个类"模块"负责在整个应用程序中获得自己的单身依赖(提供者).
现在我的问题是:
是否可以让类指定自己的依赖项,而依赖项仍然是所有其他需要相同类的类的单例.就像是:
app.ts
@Component({
selector: 'app',
providers: [
TeamCollection
]
})
@View({
template: '{{name}}'
})
class TestApp {
name: string;
teamCollection: TeamCollection;
constructor(@Inject(TeamCollection) teamCollection: TeamCollection){
this.name = 'Angular2';
this.teamCollection = teamCollection;
}
}
export function main() {
bootstrap(TestApp);
}
Run Code Online (Sandbox Code Playgroud)
team.ts
@Injectable()
export class TeamCollection extends BaseCollection {
playerCollection: PlayerCollection;
constructor(playerCollection: PlayerCollection) {
super();
this.playerCollection = playerCollection;
}
create(data: Object): TeamModel {
return new TeamModel(data);
}
}
Run Code Online (Sandbox Code Playgroud)
player.ts
@Injectable()
export class PlayerCollection extends …Run Code Online (Sandbox Code Playgroud) 我通读了另一篇文章,但似乎没有人回答我遇到的问题。是否可以具有通配符域的通配符子域(即使仅用于子域而不是子子域),如:foo.example.local。我已经可以使用example.local了,但是我不知道如何获取foo.example.local来从/ example文件夹中的/ sub / foo文件夹中抓取文件。此时的我的配置(httpd-vhost.conf):
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/www"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<Virtualhost *:80>
VirtualDocumentRoot "C:/xampp/www/%-2"
ServerName domain.local
ServerAlias *.local
<Directory "C:/xampp/www/*">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "C:/xampp/www/%-2/sub/%-3"
ServerName sub.domain.local
ServerAlias *.*.local
<Directory "C:/xampp/www/*/sub/*">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</Virtualhost>
Run Code Online (Sandbox Code Playgroud)
当前发生的情况是foo.example.local只是转到example文件夹,而不是我希望它执行的example / sub / foo文件夹。
哦,我已经启用了:LoadModule vhost_alias_module modules/mod_vhost_alias.so在httpd.conf中 …
angular ×3
apache ×1
javascript ×1
jquery ×1
jquery-ui ×1
jspm ×1
systemjs ×1
virtualhost ×1
wildcard ×1
xampp ×1