Skip to content

Instantly share code, notes, and snippets.

@maggocnx
Created July 22, 2013 07:34
Show Gist options
  • Save maggocnx/6051955 to your computer and use it in GitHub Desktop.
Save maggocnx/6051955 to your computer and use it in GitHub Desktop.
Angular Demo
function SettingsCtrl($scope, $http){
$http.get("settings.json")
.success(function(data,status){
$scope.settings = data;
});
$scope.submit = function(){
console.log($scope.settings);
$http.post("settings/", $scope.settings).
success(function(data,status){})
};
}
<!doctype html >
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>ZW 3 Settings</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="controller.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body >
<div ng-controller="SettingsCtrl" class="container">
<h1>ZW Settings</h1>
<form class="form-horizontal" method="POST" actio>
<div ng-repeat="item in settings">
<div class="control-group">
<label class="control-label" for="{{item.name}}" >{{item.text}} {{item.type}}</label>
<div class="controls" ng-switch on="item.type">
<div ng-switch-when="text">
<input ng-model="item.value" name="{{item.name}}" type="text" />
</div>
<div ng-switch-when="checkbox">
<input ng-model="item.value" name="{{item.name}}" type="checkbox" />
</div>
</div>
</div>
</div>
<button class="btn" ng-click="submit()">Save</button>
</form>
</div>
</body>
</html>
[{
"text" : "Name",
"name" : "name",
"value" : "ZW3 - 1",
"type" : "text"
},
{
"text" : "Ip Address",
"name" : "IpAddress",
"value" : "192.168.1.1",
"type" : "text"
},
{
"text" : "DHCP enabled",
"name" : "dhcpEnable",
"value" : true,
"type" : "checkbox"
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment