如何在angular和parse.com中保存数据而不进行编辑?

时间:2015-09-10 21:49:42

标签: javascript html angularjs

我想保存一个包含从表单提供信息的html。

我有这段代码:

<div ng-show="preview" class="ncontact">
  <h2 editor ng-model="newSignature.name" placeholder="Name this Signature" contenteditable="true">{{selectedtemplate.name}}</h2>
  <p editor ng-model="newSignature.templateName" ng-value = "selectedtemplate.templateName"></p>
  <div editor ng-model="newSignature.HTML" class="tdescrip" data-ng-bind-html="converted"></div>
  <span id="cancel" class="pull-right cancel cprev previews" ng-click="addSignature(newSignature)"><button>Save Signature</button></span>
  <span id="save" class="pull-left cancel previews" ng-click="signaturetemplate=true; newsignature=true; createsignature=false; preview=false;" ><button>Change Template</button></span> 
</div>

在我的控制器中

$scope.addSignature = function () {  

           var newSignature = SignatureService.newSignature($scope.newSignature);

            newSignature.then(function(result){
                $scope.signatures.unshift({name:result.get('name'), templateName:result.get('templateName'), template:$sce.trustAsHtml(result.get('HTML')),  updatedAt:result.updatedAt, objectId: result.id});
                $scope.newSignature = {name:'', templateName:'' , HTML:''};

            })
        };

在我的服务中 newSignature:function(signature){

var deferred = $q.defer();
var signatures = new Signature();
// ACL to restrict write to user, and no public access
var custom_acl = new Parse.ACL();
var user = Parse.User.current();

if(user){
  signatures.setACL(new Parse.ACL(user));
  // give write access to the current user
  custom_acl.setWriteAccess( Parse.User.current(), true);
  custom_acl.setReadAccess(Parse.User.current(), true);
  signatures.setACL(custom_acl);
}

signatures.set("name", signature.name);
signatures.set("templateName", signature.templateName);
signatures.set("HTML", signature.HTML);
//signatures.set("signatureData",{signatureData:angular.copy(signature.signatureData)});

signatures.save(null, {
  success:function(signature){

    deferred.resolve(signatures);
    signatures.save();
    console.log("saved");  
  },
  error:function(error){
    deferred.reject(error);
  }
});
return deferred.promise;

}

我想保存HTML无需编辑即可在预览中显示,但当保存为空时,当我添加contenteditable=true <div editor ng-model="newSignature.HTML" class="tdescrip" data-ng-bind-html="converted"></div>时,该功能会保存模板,但我不会我希望如此,我想保存预览中显示的模板。

0 个答案:

没有答案