1
$ 리소스를 이해하려고하는데 어디서부터 시작해야할지 모르겠다. REST API를 사용하여 데이터를 db에 저장하려고합니다. 그런 다음이 내 각 코드이지만, 나는 그들이 플러시됩니다 refres 경우 지금은 데이터를 추가 할 경우, 그들은 만 캐시에 추가됩니다
<ion-view title="Add New Device" ng-controller="addDevice">
<ion-content>
<form name="addDeviceForm" ng-init="setFormScope(this)" data-ng-submit="deviceSubmit()">
<div class="list" style="background:#ffffff;">
<div class="item item-divider">
Device Info
</div>
<label class="item item-input item-stacked-label">
<span class="input-label">Name</span>
<input type="text" placeholder="Name" ng-model="newDevice.name">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Icon</span>
<input type="text" placeholder="Icon" ng-model="newDevice.icon">
<select ng-model="newDevice.icon" ng-options="ionicon.name for ionicon in ionicons"></select>
</label>
<div class="item item-divider">
Location
</div>
<label class="item item-input item-select">
<div class="input-label">
Select a Location
</div>
<select ng-model="newDevice.locationSelect" ng-options="o.id as o.name for o in locations"></select>
</label>
<div class="item item-divider">
Select Action
</div>
<label class="item item-input item-select">
<div class="input-label">
Action
</div>
<select ng-model="newDevice.actionSelect" ng-options="o.id as o.name for o in actions"></select>
</label>
<div class="item item-divider">
Featured
</div>
<li class="item item-toggle">
Featured
<label class="toggle toggle-balanced">
<input type="checkbox" checked ng-model="newDevice.featured">
<div class="track">
<div class="handle"></div>
</div>
</label>
</li>
</div>
<div class="padding">
<button class="button button-balanced" ng-click="">
Add Device
</button>
</div>
</form>
</ion-content>
:
이
은 내 양식입니다 그래서 DB에 영구 변경을 가하고 데이터를 추가하려고합니다. " "뭔가 ".controller('addDevice', function ($scope) {
$scope.setFormScope = function (scope) {
this.formScope = scope;
};
$scope.newDevice = {};
$scope.deviceSubmit = function() {
if (!$scope.newDevice.name) {
$scope.showAlert('Name Required');
return;
}
if (!$scope.newDevice.icon) {
$scope.newDevice.icon = 'ion-ios7-lightbulb-outline';
}
if ($scope.newDevice) {
$scope.showAlert('Device Added');
}
$scope.newDevice.id = $scope.devices.length + 2;
$scope.devices.push($scope.newDevice);
this.formScope.addDeviceForm.$setPristine();
var defaultForm = {
id: "",
name: "",
icon: "",
status: "",
color: "",
userSelect: "",
actionSelect: "",
locationSelect: ""
};
$scope.newDevice = defaultForm;
};
})
또한이 POST 옵션을 선택하고 HEAD 를 GET 받아들이는 경로/API/장치 /입니다 그리고 이것은이 같아야하는 방법입니다
{ "이름 " 호스트 ":"뭔가 ", "아이콘 ":"뭔가 ", "상태 ":"뭔가 ", "기능을 갖춘 "부울, "핀 "나는 시작해야 1 }
을 :( 고맙습니다.