所以我試圖複製節div(所以我可以有多個文章的多個部分)。我試圖使用相同的控制器爲兩個div如下所示。所以我可以通過將它添加到main來添加該部分,但我無法編輯第二個div。有沒有辦法解決?使用相同的控制器爲兩個相同的div與不同的數據和使用可編輯的第二個div
我不使用引導程序,我使用xeditable。
HTML:
<div id="main" ng-app="main">
<div class = "section" ng-controller="newsController">
<h2 id="section" editable-text="sections.section">{{sections.section}}</h2>
<div class = "article" ng-repeat="article in sections.articles">
<h3 id="title" editable-text="article.title"><a editable-text="article.link" href="{{article.link}}">{{article.title}}</a></h3>
<p id="publisher" editable-text="article.publisher">{{article.publisher}}</p>
<p id="orig_title" editable-text="article.orig_title">{{article.orig_title}}</p>
<p id="descr" ng-bind-html="article.description" editable-text="article.description"></p>
</div>
<div class = "section" ng-controller="newsController">
</div>
</div>
JS:
newsletter.controller('newsController',function($scope){
$scope.sections = {
section: "Faculty",
articles: [
{
title: "In __ We Trust",
link:'http://wee.com',
publisher: "Me",
orig_title:"",
description: "Description Here"
}
]
};
$scope.addItem = function(){
$scope.sections.articles.push(this.sections.articles.temp);
$scope.sections.articles.temp={};
};
)};
var newSection = '//Pretend all the tags and the attributes as above are placed here'
$("#add-section").click(function(){
var $section = $('#main').append(newSection);
});
道歉格式。我還是這個新手。謝謝!
編輯:我也試圖使這種動態,使用戶可以編輯文本,如標題和出版商等。我怎樣才能使添加的部分也可編輯?
如果是完全一樣的行爲,你應該使用指令代替。 –
而且你也不應該使用jQuery。 –
你能解釋爲什麼我不應該使用jQuery嗎?我仍然試圖瞭解角度和東西 – smirkin