0
嗨我試圖列出從下拉框中選擇的項目,並使用angularjs.so在表中顯示它。這裏是代碼,從下拉框中選定的項目,並以表格格式顯示
https://plnkr.co/edit/8qCgB2flMGB89moppkz6?p=preview
abc.html
Car Brand:
<select name="carname" ng-model="userSelect" required>
<option value="">--Select--</option>
<span ng-show="valdate.carname.$error.required">Car name</span>
<option ng-repeat="ManufactureBrand in a" ng-bind="ManufactureBrand" >
{{ManufactureBrand}}
</option>
</select>
<br/>
<br/> Car Model:
<select name="carmodel" ng-model="selectCar" required>
<option value="">--Select--</option>
<span ng-show="valdate.carmodel.$error.required">Car name</span>
<option ng-repeat="CarName in b" ng-bind="CarName">
{{CarName}}
</option>
</select>
<br/>
<input type="submit" ng-click="checkselection()" ng-disabled="valdate.carname.$invalid && valdate.carmodel.$invalid">
<table>
<tr>
<th>Car Name</th>
<th>Car Model</th></tr>
<tr>
<td>{{list}}</td>
<td>{{carlist}}</td>
</tr>
</table>
abc.js
var app = angular.module('carService', []);
app.factory('Brandtest', function() {
var brand = {};
brand.sample = ['Bmw', 'Mercedes', 'Honda'];
brand.car = ['Suv', 'Sedan', 'Cope'];
{
return brand;
}
});
app.controller('selectDropdown', ['$scope', 'Brandtest', function ($scope, Brandtest) {
$scope.a = Brandtest.sample;
$scope.b = Brandtest.car;
$scope.list=[];
$scope.carlist=[];
$scope.checkselection = function() {
if ($scope.userSelect != "" && $scope.userSelect != undefined &&
$scope.selectCar != "" && $scope.selectCar != undefined)
{
$scope.list.push($scope.userSelect);
$scope.carlist.push($scope.selectCar);
}
我還附加了圖片,顯示了我的最終結果。
此處列表中所有列表中的項目在同一行中重疊。 因此,請幫助我正確顯示錶格,並從下拉菜單中提交選定的項目,我希望它們能夠一個在另一個下面。
對不起圖像文件didnt正常上傳。 – Rudhra
可以使你的代碼plunkr鏈接將很容易爲所有人解決您的問題 –
URL添加@MBalajivaishnav – Rudhra