(function(angular) { | |
'use strict'; | |
angular.module('learnAngular', []) | |
.controller('postExample', ['$scope', '$http', function($scope, $http) { | |
$http({ | |
url: 'http://joshpress.net/wp-json/wp/v2/posts/1', | |
cache: true | |
} ).then( function( res ) { | |
$scope.post = res.data; | |
}); | |
}]).controller('postsExample', ['$scope', '$http', function($scope, $http) { | |
$http( { | |
url: 'http://joshpress.net/wp-json/wp/v2/posts/', | |
cache: true | |
} ).then( function ( res ) { | |
$scope.posts = res.data; | |
$scope.totalPages = res.headers('x-wp-totalpages'); | |
$scope.total = res.headers( 'x-wp-total' ); | |
} ); | |
}]); | |
})(window.angular); |
(function(angular) { | |
'use strict'; | |
angular.module('learnAngular', []) | |
.controller('postExample', ['$scope', '$http', function($scope, $http) { | |
$http({ | |
url: 'http://joshpress.net/wp-json/wp/v2/posts/1', | |
cache: true | |
} ).then( function( res ) { | |
$scope.post = res.data; | |
}); | |
$scope.save = function(){ | |
$http({ | |
url: 'http://joshpress.net/wp-json/wp/v2/posts/1', | |
cache: true, | |
method: "POST" | |
} ).then( function( res ) { | |
$scope.post = res.data; | |
}); | |
}; | |
}]).controller('postsExample', ['$scope', '$http', function($scope, $http) { | |
$http( { | |
url: 'http://joshpress.net/wp-json/wp/v2/posts/', | |
cache: true | |
} ).then( function ( res ) { | |
$scope.posts = res.data; | |
$scope.totalPages = res.headers('x-wp-totalpages'); | |
$scope.total = res.headers( 'x-wp-total' ); | |
} ); | |
}]); | |
})(window.angular); |
ingotApp.factory( 'groupsFactory', function( $resource ) { | |
return $resource( INGOT_ADMIN.api + 'groups/:id', { | |
id: '@id', | |
_wpnonce: INGOT_ADMIN.nonce, | |
context: 'admin' | |
},{ | |
'query' : { | |
transformResponse: function( data, headers ) { | |
var response = { | |
data: data, | |
headers: headers() | |
}; | |
return response; | |
} | |
}, | |
'update':{ | |
method:'PUT', | |
headers: { | |
'X-WP-Nonce': INGOT_ADMIN.nonce | |
} | |
}, | |
'post':{ | |
method:'POST', | |
headers: { | |
'X-WP-Nonce': INGOT_ADMIN.nonce | |
} | |
}, | |
'save':{ | |
method:'POST', | |
headers: { | |
'X-WP-Nonce': INGOT_ADMIN.nonce | |
} | |
}, | |
'delete':{ | |
method:'DELETE', | |
headers: { | |
'X-WP-Nonce': INGOT_ADMIN.nonce | |
} | |
} | |
}) | |
}); |
ingotApp.controller( 'clickDelete', ['$scope', 'groupsFactory', function( $scope, groupsFactory ){ | |
groupsFactory.query( | |
{ | |
page: 1, | |
limit: 10, | |
context: 'admin', | |
type: 'click' | |
}, function ( res ) { | |
if ( res.data.indexOf( 'No matching' ) > -1 ) { | |
$scope.groups = {}; | |
return; | |
}; | |
$scope.groups = JSON.parse( res.data ); | |
var total_groups = parseInt( res.headers[ 'x-ingot-total' ] ); | |
total_pages = total_groups / page_limit; | |
$scope.total_pages = new Array( Math.round( total_pages ) ); | |
$scope.groups.shortcode = []; | |
}); | |
}]); |
$http({ | |
url: 'http://joshpress.net/wp-json/wp/v2/posts/1', | |
} ).then( function( res ) { | |
$scope.post = res.data; | |
}); |
<div ng-controller="postExample"> | |
<form> | |
<input type="text" ng-model="post.title" /> | |
</form> | |
<div>{{post.title}}</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
jeam458 commentedNov 8, 2018
really nice