【发布时间】:2014-08-24 20:01:54
【问题描述】:
我正在尝试这样做,以便我可以在我的 angularJS 应用程序中添加一个带有按钮的文本区域。可以有尽可能多的用户喜欢的文本区域,用于向向导系统添加内容。显然,每个 textarea 都需要不同的 ID(因为我计划将其发送到 API),所以我在主控制器的范围内创建了一个 stageIndex 变量。然后在我的新阶段指令中,我将其添加到父 div 与另一个 textarea 与 stageIndex 作为 id.... 但它只是出现 NaN 而不是我指定的数字。有任何想法吗? app.controller("admin", function($scope, $location, $http, $state){
app.controller("admin", function($scope, $location, $http, $state){
$scope.stageIndex = 0;
// My other code here
});
app.directive('newstage', function(){ // This is my buttons directive, hence the element.click()
return function(scope, element, attrs){
element.click(function($scope){
$scope.stageIndex += 1;
element.parent().append("<textarea ng-attr-id="+ 'stage-' + $scope.stageIndex +"></textarea>");
});
}
});
【问题讨论】:
标签: angularjs