在我的应用程序中,我必须获取一些JSON数据并在加载页面之前将其分配给数组.这是我使用CardService服务获取JSON的代码:
cards = [];
var cs = {
...
fetchCards: function() {
var d = $q.defer();
$http.get("data/cards.php").success(function(data) {
cards = data;
d.resolve();
}).error(function(data, status) {
d.reject(status);
});
return d.promise;
},
getCards: function() { return cards; };
...
}
Run Code Online (Sandbox Code Playgroud)
在控制器的解析块中,我有以下内容:
WalletController.resolve = {
getCards: function(CardService) {
CardService.fetchCards().then(loadView, showError);
}
}
Run Code Online (Sandbox Code Playgroud)
在实际的控制器中,我有以下内容:
function WalletController($scope, CardService) {
$scope.cards = CardService.getCards();
}
Run Code Online (Sandbox Code Playgroud)
问题是,服务中的fetchCards函数似乎在将JSON数据分配给cards变量之前解析了promise.这导致我的视图加载空白数据,直到我刷新几次并获得幸运.
我可以确认延迟加载,因为当我在控制台中记录卡片变量时,我在第122行(当我的视图加载时)得到一个空数组,在第57行得到一个完整数组(当JSON调用成功时).第57行代码在加载视图后以某种方式执行.
我该如何解决?
我有一个表格,我希望用户编辑他想要收到的杂志订阅.代码如下:
零件:
export class OrderFormComponent {
subscriptions = [
{id: 'weekly', display: 'Weekly newsletter'},
{id: 'monthly', display: 'Monthly newsletter'},
{id: 'quarterly', display: 'Quarterly newsletter'},
];
mySubs = [
this.subscriptions[1]
]
order = new FormGroup({
subs: new FormArray(this.mySubs.map(sub => new FormControl(sub)), Validations.required) //Lost at this part
});
}
Run Code Online (Sandbox Code Playgroud)
模板:
<form [formGroup]="order">
<div formArrayName="subs">
<label>Sign me up for newsletters</label>
<p *ngFor="let s of subscriptions; let i=index">
<input type="checkbox" [value]="s.id" [formControlName]="i" /> {{ s.display }}
</p>
</div>
<div>
<input type="checkbox" formControlName="agree" /> I …Run Code Online (Sandbox Code Playgroud) 在游戏中!框架,我可以执行以下操作来干掉我的布局代码:
在main.html中:
<h1>This is main</h1>
#{doLayout /}
<div id="footer">Footer content</div>
Run Code Online (Sandbox Code Playgroud)
在home.html:
#{extends 'main.html' /}
<p>This is the home page content</p>
Run Code Online (Sandbox Code Playgroud)
我想在AngularJS中做同样的事情,即我想创建一个HTML文件并让它继承自另一个.我看到有ngInclude指令,但使用它会导致当前应用程序中的大量布局代码重复.如果AngularJS本身不支持它,那么还有其他任何HTML模板解决方案吗?
谢谢.
有没有办法将接口作为varargs参数传递给groovy中的方法?
这是我正在尝试做的事情:
interface Handler {
void handle(String)
}
def foo(Handler... handlers) {
handlers.each { it.handle('Hello!') }
}
foo({ print(it) }, { print(it.toUpperCase()) })
Run Code Online (Sandbox Code Playgroud)
当我运行以下代码时,我收到错误:
No signature of method: ConsoleScript8.foo() is applicable for argument types: (ConsoleScript8$_run_closure1, ConsoleScript8$_run_closure2) values: [ConsoleScript8$_run_closure1@4359df7, ConsoleScript8$_run_closure2@4288c46b]
我需要改变什么?