嗨,现在有了这段代码,我能够将文本框值添加到数组中,并在将值添加到数组后清空文本框。现在我的问题是为文本框添加所需的验证。如果在文本框或数组中存在值,则应删除所需的验证。否则应添加。请帮助我。
<div class="input-group">
<input ng-disabled="$parent.BuildModel.DisableControl" type="text" class="form-control textBoxStyle " name="Logpath" ng-model="$parent.BuildModel.Logpath" id="Logpath" required />
<span class="input-group-addon ">
<button ng-click="onclickfun();">
<i class="glyphicon glyphicon-plus"></i>
</button>
</span>
</div>
<span ng-disabled="$parent.BuildModel.DisableControl" class="help-block" name="LogPaths" id="LogPaths" ng-model="$parent.BuildModel.LogPaths" >{{LogPaths}}</span>
在控制器中
$scope.BuildModel.LogPaths = [];
$scope.onclickfun = function () {
if ($scope.BuildModel.LogPath.length < 0) {
Alertify.alert("Please enter log path for adding to list");
}
$scope.BuildModel.LogPaths.push($scope.BuildModel.LogPath);
console.log($scope.BuildModel.LogPaths);
$scope.BuildModel.LogPath = ClientConfig.EMPTY;
$scope.BuildModel.res = $scope.BuildModel.LogPaths.join(' ');
};
答案 0 :(得分:0)
您正在使用$parent
,但不需要使用它。我为此创建了一个简单的示例。您可以在HERE
html
<div ng-app ng-controller="LogController">
<input ng-model="inputData"></input>
<input type="submit" ng-click="addPath()" value="add"></input>
<div ng-repeat="log in logs">{{ log }}</div>
</div>
控制器
function LogController($scope) {
$scope.logs = [];
$scope.addPath = function () {
$scope.logs.push($scope.inputData);
$scope.inputData = null;
};
}