patternjavascriptMinor
Basic and simple view, add, edit and delete functionality
Viewed 0 times
editsimpledeletebasicviewandfunctionalityadd
Problem
I want to know what needs to improve with my application. Maybe there is a better way instead of what I am using currently.
index.html:
list.html:
details.html:
new.html:
app.js:
controller.js:
```
var logController = angular.module('logController', []);
var logData = null;
logController.controller('ListController', ['$scope', '$http', function ($scope, $http) {
$http.post('testws.asmx/GetUsers', {
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}).success(function (data) {
$scope.logs = data.d;
$scope.orderRecord = 'Id';
logData = $scope.logs;
})
} ]);
logController.controller('DetailsController', ['$scope', '$http', '$routeParams', '$location', function ($scope, $htt
index.html:
Angular JS
My App
list.html:
New
Id
LastName
Ascending
Descending
{{item.Id}}
{{item.FirstName}}
{{item.LastName}}
{{item.Mi}}
Edit
details.html:
Id:
FirstName:
LastName:
Mi:
new.html:
FirstName:
LastName:
Mi:
app.js:
var myApp = angular.module('MyApp', [
'ngRoute',
'logController'
]);
myApp.config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/list', {
templateUrl: 'partials/list.html',
controller: 'ListController'
}).
when('/details/:itemId', {
templateUrl: 'partials/details.html',
controller: 'DetailsController'
}).
when('/new', {
templateUrl: 'partials/new.html',
controller: 'NewController'
}).
otherwise({
redirectTo: '/list'
});
}]);controller.js:
```
var logController = angular.module('logController', []);
var logData = null;
logController.controller('ListController', ['$scope', '$http', function ($scope, $http) {
$http.post('testws.asmx/GetUsers', {
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}).success(function (data) {
$scope.logs = data.d;
$scope.orderRecord = 'Id';
logData = $scope.logs;
})
} ]);
logController.controller('DetailsController', ['$scope', '$http', '$routeParams', '$location', function ($scope, $htt
Solution
Interesting,
a readable Angular submission, I quite like it.
The only trouble I see is that
only the URL and the original data is different for your call to
I like how this code seems compatible with older IE's without too many hacks.
a readable Angular submission, I quite like it.
The only trouble I see is that
controller.js has some serious copy pastage, you might want to consider a helper function for this part:$http.post('testws.asmx/AddUser', JSON.stringify(user), {
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}).success(function (data) {
$location.path("/list");
}).error(function (err) {
alert(err.Message);
});only the URL and the original data is different for your call to
'testws.asmx/DeleteUser' and testws.asmx/AddUser.I like how this code seems compatible with older IE's without too many hacks.
Code Snippets
$http.post('testws.asmx/AddUser', JSON.stringify(user), {
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}).success(function (data) {
$location.path("/list");
}).error(function (err) {
alert(err.Message);
});Context
StackExchange Code Review Q#54475, answer score: 2
Revisions (0)
No revisions yet.