harimau99
5/6/2018 - 11:54 AM

1.js

(function(angular) {
    'use strict';
    angular.module('learnAngular', [])
        .controller('postExample', ['$scope', function($scope) {
            $scope.post = {
                title: 'Enter Title'
            };

        }]);
})(window.angular);
<div ng-controller="postExample">
    <form ng-submit="submit()">
        <input type="text" ng-model="post.title" />
        <input type="submit" value="Save" ng-hide="post.title == 'Enter Title'" />
    </form>
    <div>{{post.title}}</div>
</div>
(function(angular) {
    'use strict';
    angular.module('learnAngular', [])
        .controller('postExample', ['$scope', function($scope) {
            $scope.post = {
                title: 'Enter Title'
            };
            $scope.submit = function(){
              alert( 'saving' );
            }

        }]);
})(window.angular);
<div ng-controller="postsExample">
        <h3>Posts:</h3>
        <div ng-repeat="post in posts">
          {{post.title}}
        </div>
</div>
.controller('postExample', ['$scope', function($scope) {
            $scope.post = {
                title: 'Enter Title'
            };

        }] ).controller('postsExample', ['$scope', function($scope) {
            $scope.posts = [
                { title: 'Post One' },
                { title: 'Post Two' }
            ];

    }]);
(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>