2016-08-15 70 views
1

我的文本編輯器模型值不是綁定,也是類型爲textarea的,並且我在其中具有html格式的文本。當我調用我的save方法時,這個編輯器的模型變量是null。我無法理解爲什麼會發生這種情況,因爲具有簡單輸入類型文本的模型工作正常,可能是文本編輯器模型的問題。以下是我的代碼,請親切看看這個,可能是我做錯了什麼。模型值不與編輯器綁定Angularjs

<div class="col-md-12"> 
        <div class="form-group"> 
         <input type="text" ng-model="TemplateName" class="form-control" placeholder="Enter Template Name">        
        </div> 
        <div class="form-group"> 
         <textarea cols="18" rows="40" class="wysihtml5 wysihtml5-min form-control" id="templateDescription" ng-bind-html="TemplateDescription" placeholder="Enter Agreement Template ..." ></textarea> 
        </div> 
       </div> 

這是我的控制器代碼:

$scope.Template = { 
      Name: $scope.TemplateName, 
      Description: $scope.TemplateDescription,     
     }; 

     var promisePost = templateService.post($scope.Template); 
      promisePost.then(function (pl) { 

       //success message 

      }, function (err) { 

       //error message 

      }); 
+0

什麼不excatly結合。 'TemplateName'或'TemplateDescription' –

回答

1

您應該使用ng-model直接綁定它Template.Description

HTML

<div ng-app> 
    <div ng-controller="sampleCtrl"> 
    <textarea cols="18" rows="40" class="wysihtml5 wysihtml5-min form-control" id="templateDescription" ng-model="Template.Description" placeholder="Enter Agreement Template ..."></textarea> 
    {{Template.Description}} 
    </div> 
</div> 

控制器

function sampleCtrl($scope) { 
    $scope.Template = { 
    Description: '' 
    }; 
} 

,供您參考,請參閱this fiddle

+0

感謝您的時間,但這並不適合我,因爲它包含原始html,所以它給了我未定義的模型。 – usman

+0

你能創建一個小提示,顯示你在說什麼嗎? –

+0

你的回答也幫助和最後抓到了問題,編輯腳本毀了所有的派對, – usman

0

使用ng-model,而不是ng-bing-html

<div class="col-md-12"> 
    <div class="form-group"> 
     <input type="text" ng-model="TemplateName" 
     class="form-control" placeholder="Enter Template Name">        
    </div> 
    <div class="form-group"> 
     <textarea cols="18" rows="40" 
     class="wysihtml5 wysihtml5-min form-control" id="templateDescription" 
     ng-model="TemplateDescription" 
     placeholder="Enter Agreement Template ..." ></textarea> 
    </div> 
</div> 

檢查我的筆http://codepen.io/keephacking/pen/kXVjOX?editors=1010

1

是使用ng-model結合

HTML作爲

div class="form-group"> 
    <input type="text" ng-model="TemplateName" class="form-control" placeholder="Enter Template Name"> 
</div> 
<div class="form-group"> 
    <textarea cols="18" rows="40" class="wysihtml5 wysihtml5-min form-control" id="templateDescription" 
    ng-bind-html="TemplateDescription" 
    ng-model='TemplateDescription' // add ng-model 
    placeholder="Enter Agreement Template ..."></textarea> 
</div> 

這裏是plnkr link

+0

我的編輯器包含原始html,這個返回我undefined – usman

+0

我檢查了它的綁定。不知道你確切的問題是什麼 –