角度服务无法正常工作
Angular service not working properly
我正在使用Angular(客户端)和Node(服务器端)构建一个应用程序。我在 Angular 中使用了一些 API,但坚持从特定 API 检索数据。有人可以帮忙吗?
这是我的 API 的响应 JSON:
{
"devices": [
{
"name": "led1",
"driver": "Led",
"connection": "driver",
"commands": [
"is_on",
"turn_on",
"turn_off",
"toggle",
"brightness",
"current_brightness"
],
"details": {
"pin": 12
}
},
{
"name": "led2",
"driver": "Led",
"connection": "driver",
"commands": [
"is_on",
"turn_on",
"turn_off",
"toggle",
"brightness",
"current_brightness"
],
"details": {
"pin": 13
}
},
{
"name": "sensor",
"driver": "AnalogSensor",
"connection": "driver",
"commands": [
"analog_read"
],
"details": {
"pin": 0
}
}
]
}
这是我的角度服务:
angular.module('robots.services', ['ngResource'])
.factory('Robots', function($resource) {
return $resource(
'http://dionaudio.local:8090/api/robots/Dionaudio.local/devices/:devices',
{ //method: 'robots', q: 'robots'
}, // Query parameters
{'query': { method: 'GET' }}
);
});
控制器和应用程序.js
.controller('RobotsCtrl', function($scope, Robots) {
$scope.robots = Robots.query();
});
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.robots', {
url: "/robots",
views: {
'menuContent': {
templateUrl: "templates/robots.html",
controller: 'RobotsCtrl'
}
}
})
.state('app.deviceinfo', {
url: "/deviceinfo",
views: {
'menuContent': {
templateUrl: "templates/deviceinfo.html",
controller: 'DeviceinfoCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/deviceinfo');
});
最后是我的模板:
<ion-item ng-repeat="robot in robots" href="">{{robot.name}}</ion-item>
我只得到一个结果,没有名称输出。我做错了什么?
我认为您需要指向 json 中的数组
<ion-item ng-repeat="robot in robots.devices" href="">{{robot.name}}</ion-item>
对于下面的问题,您需要类似
.state('app.robots', {
url: "/robots/:robotName",
views: {...
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 正在尝试使用if和else添加类,但无法正常工作
- Jquery FadeIn FadeOut 只工作一次
- Foreach无法在Typescript中工作
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- JS可以在Chrome中工作,但不能在Firefox中工作
- 最大高度转换不;不工作,工作缓慢
- Gulp-rev:不是第一次工作,而是在第一次工作之后工作
- JQuery - Ajax: encodeUriComponent不工作(EncodeUri工作)