2016-10-03 92 views
0

我試圖用離子列表來顯示一組汽車,當選擇特定的汽車時,它應該顯示它的一個小的描述,也可編輯。這裏我無法顯示所選項目的描述。同時請讓我知道如何編輯描述並更新它。瞭解離子選擇

link here

這是控制器

car.controller('popSelect', ['$scope','$ionicPopup', function ($scope, $ionicPopup) { 
    $scope.homePage = function() { 
    window.location = "#/menu.html" 
    } 

    $scope.carList = [{ value: "Honda", description: "Its honda" }, 
    { value: "Toyota", description: "Its Toyota" }, 
    { value: "BMW", description: "Its BMW" }]; 
    //$scope.carList=['Bmw','Mercedes','Honda']; 
    $scope.select_item = function (key) { 
    {{item.decription}} 
    } 
}]); 

回答

0

變化的Index.html

<body ng-app="myApp" ng-controller="myCtrl"> 
    <h4>Select car</h4> 
    <ion-list> 
     <ion-item ng-click="select_item(value)" ng-repeat="(key,value) in carList"> 

     {{value.value}} 

     </ion-item> 
    </ion-list><hr> 
      <div style="text-align:center"> 
    <button class="button3" ng-click="showPopup()">ADD</button><hr> 
    <button class="button2" ng-click="homePage()">Back</button> 
    <button class=" button2" ng-click="deleteSelected()">Delete</button> 
     </div> 
     <div>{{description}}</div> 
    <!--{{couponTitle}} {{couponDescribe}} {{validFrom}} {{validTo}} --> 
    </body> 

在你的js

var car=angular.module('myApp',[]); 
car.controller('myCtrl', ['$scope', function ($scope) { 
    $scope.homePage = function() { 
    window.location = "#/menu.html" 
    } 
// $scope.description = ''; 
    $scope.selectedItem = 'select'; 
    $scope.items=[]; 
    $scope.carList = [{ value: "Honda", description: "Its honda" }, 
    { value: "Toyota", description: "Its Toyota" }, 
    { value: "BMW", description: "Its BMW" }]; 
    //$scope.carList=['Bmw','Mercedes','Honda']; 
    $scope.select_item = function (key) { 
    $scope.description=key.description; 
    } 
}]); 

感謝(Y)

+0

我能知道爲什麼使用$ scope.items.push(key)?.如果我使用它,我將能夠編輯描述並更新新的描述。 – sree

+0

只是這樣你可以添加多個描述並顯示它們......並且還可以對它們進行特定的操作:) –

+0

絕不會在js文件中使用{{item.decription}}這些表達式,它的html將根據您的範圍變量(Y) –