angularjs - Angular model not injecting rest call when trying to UPDATE -


so new angular , node go easy on me. have been building rest api profile site , requires updating of posts. have get, delete , create working stuck trying current post object (from stateparams) inject editor.

// uses sateparams object id  .controller('editpostctrl', ['$scope', 'post',        '$stateparams', '$state', function($scope, post,        $stateparams, $state) {      $scope.action = 'edit';      $scope.isdisabled = true;            $scope.post = post.findbyid({ id: $stateparams.id })      .$promise            }])
<h1>post editor</h1>  <form name="form" ng-submit="submitform()">  		<div class="form-group">  			<!-- if error -->  		  			<!-- blog title -->  			<label>title:</label>	  			<input type="text" class="form-control" placeholder="example title" autocomplete="off" required ng-model="post.title"></input>  			<br />    			<!--  			<label>author:</label>  			<input type="text" class="form-control" autocomplete="off" placeholder="{{ author }}" required ng-model="post.author"></input>  			<br />  			-->    			<!-- date -->  			<label>date:</label>  			<input type="date" class="form-control" required ng-model="post.date"></input>  			<br />  		  			<!-- post content -->  			<label>blog content:</label>  			<div ng-controller="editorctrl">  			<textarea type="text" class="ck-editor" autocomplete="off" required ng-model="post.content"></textarea>  			</div>  		  			<div class="pull-right buttonspacer">  				<a href="posts" class="btn btn-default btn-lg">cancel</a>   				<button class="btn btn-default btn-lg">{{ action }}</button>  			</div>  		</div>  </form>

 .controller("editpostctrl", function($scope,$http){  $scope.submitform = function(id) {     $http.post('/api/postid/' + id)         .success(function(data) {             $scope.action = 'edit';             $scope.isdisabled = true;             console.log(data);         })         .error(function(data) {             console.log('error: ' + data);         }); }; }); 

in angularjs,

you can use ng-click e.g.

     <button class="btn btn-default btn-lg" ng-click="submitform(post._id)">{{ action }}</button> 

can try this


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -