我如何使用 ng-repeat 在 UI 上使用 angularJS 迭代来自服务器的 JSON 响应?
$scope.data = {
"Home Needs": [{
"id": 11,
"itemName": "PARLE G 500 Grams",
"itemPrice": 50,
"minSellPrice": 45,
"discount": 0,
"store": "Home Needs"
}],
"SRI SAI Store": [{
"id": 1,
"itemName": "PARLE G 500 Grams",
"itemPrice": 50,
"minSellPrice": 45,
"discount": 0,
"store": "SRI SAI Store"
}],
"Ashirwad": [{
"id": 10,
"itemName": "PARLE G 500 Grams",
"itemPrice": 50,
"minSellPrice": 46,
"discount": 0,
"store": "Ashirwad"
}]
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我使用 jsfiddle 或指针吗?
谢谢
angularjs angularjs-directive angularjs-scope angularjs-ng-repeat
如果Javascript函数设计有回调,那么如何在AngularJS promise中封装该函数?
例如,我在看使用以下科尔多瓦插件:cordova.plugins.diagnostic(见https://www.npmjs.com/package/cordova.plugins.diagnostic).它的许多功能都设计有回调功能.因为请求正在使用设备的操作系统,所以在函数完成之前可能需要一些时间,因此我正在考虑是否应该在promise结构中调用它们.例如,如何转换以下内容:
cordova.plugins.diagnostic.isWifiEnabled(function(enabled){
<do something>
}, function(error){
<do something>
});
Run Code Online (Sandbox Code Playgroud)
或者实际上任何通用的回调结构......
masterFunction(function(enabled){
<do something>
}, function(error){
<do something>
});
Run Code Online (Sandbox Code Playgroud)
在AngularJS承诺中运作?它会是这样的吗?
function callMasterFunction() {
var deferred = $q.defer();
masterFunction(function(enabled){
<do something>
deferred.resolve(enabled);
}, function(error){
<do something>
deferred.resolve(error);
});
return deferred.promise;
}
Run Code Online (Sandbox Code Playgroud)
我认为当使用AngularJS和Cordova以及W3C Geolocation API时,这也是一个问题.在我看来,我可能没有清楚地了解在这些情况下如何管理范围.
最终,我可以看到将这些类型的呼叫链接在一起.就像是:
var promise = callMasterFunction1()
.then(function(response) { return callMasterFunction2(); })
.then(function(response) { return callMasterFunction3(); })
...
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.感谢您的时间.
如何使用 ng-repeat 指令获取数组最后一个索引 + 1 ?动态 Profile.addresses[2].site_name
<tr ng-repeat="lines in array">
<td>
<input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].site_name ' name='site_name'>
</td>
<td>
<input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].street_address ' name='street_address'>
</td>
<td>
<input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].city ' name='city'>
</td>
<td>
<input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].state ' name='state'>
</td>
<td>
<input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].country ' name='country'>
</td>
<td>
<input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].zip_code ' name='zip_code'>
</td>
<td>
<input type="text" class="form-control" id="inputDefault" ng-model=' Profile.addresses[2].phone_number ' name='phone_number'> …Run Code Online (Sandbox Code Playgroud) 我有这个js代码
var app = angular.module('app', []);
app.service('testService', function(){
this.sayHello= function(text){
return "Service says \"Hello " + text + "\"";
};
this.sayGoodbye = function(text){
return "Service says \"Goodbye " + text + "\"";
};
});
app.controller('AboutCtrl', ['testService', function ($scope, $location, $http) {
$scope.fromService = testService.sayHello("World");
$scope.toService = testService.sayGoodbye("World");
}]);
Run Code Online (Sandbox Code Playgroud)
在我的HTML中我有这个.... ...嗨{{fromService}} .... ...控制台中没有错误,页面只是空白.
angularjs angularjs-directive angularjs-service angularjs-scope
我需要重复特定元素一定次数,而不是重复所有元素.
<div ng-repeat='el in elements'>
<div>{{el.someValue}}</div>//repeat here only 3 times
<div>{{el.someValue}}</div>// repeat here only 2times something like this
</div>
Run Code Online (Sandbox Code Playgroud)
我可以这样做吗?
angularjs angularjs-directive angularjs-scope angularjs-ng-repeat
我有一个angularJS指令,通过以下方式调用:
<rpt-closing closing-begin-ts="null" closing-begin-ts="'2014-11-25 23:59:59'"></rpt-closing>
Run Code Online (Sandbox Code Playgroud)
指令代码如下:
.directive('rptClosing',function(){
return {
restrict:'E',
scope: {
closingBeginTs: '=',
closingEndTs: '='
},
link: function(scope, element, attrs) {
console.log('*******************************************');
console.log('scope = ', scope);
console.log('scope.closingBeginTs = ', scope.closingBeginTs);
console.log('scope.closingEndTs = ', scope.closingEndTs);
console.log('*******************************************');
},
template: '<div>BLAH BLAH BLAH</div>'
};
}
)
Run Code Online (Sandbox Code Playgroud)
这段代码在jsFiddle中运行得非常好.我能看到的价值scope.closingBeginTs,并scope.closingEndTs在控制台输出.