AngularJS:控制器的功能

时间:2018-01-25 16:24:54

标签: angularjs

我在我的应用程序中使用AngularJS时遇到问题。特别是,当我必须调用我在控制器部分编写的函数时,它不起作用。 任何人都知道我该怎么做。感谢。

这是我的代码......给我一些问题的函数叫做totale()。

var app = angular.module('pizza', []);


app.controller('a1', function ($scope) {
    
    
    $scope.listino = [
         {id: 1, nom: 'Marinara', prezzo: 3.00},
         {id: 2, nom: 'Margherita', prezzo: 4.50},
         {id: 3, nom: '4 Formaggi', prezzo: 6.50},
         {id: 4, nom: 'Carbonara', prezzo: 6.00},
         {id: 5, nom: 'Boscaiola', prezzo: 7.00},
         {id: 6, nom: 'Patatosa', prezzo: 5.50},
         {id: 7, nom: 'Capricciosa', prezzo: 6.00},
    ];

      
    $scope.paste = [
        {n: 1, nome: 'Tradizionale'},
        {n: 2, nome: 'Integrale'}
    ];

    $scope.basi = [
        {n: 1, nome: 'Pomodoro', prezzo: 1.50},
        {n: 2, nome: 'Bianca',  prezzo: 0}
    ];

    $scope.ingredienti = [
        {n: 1, nome: 'Verdure', prezzo: 1.50, select: false},
        {n: 2, nome: 'Affettati',  prezzo: 1.85, select: false},
        {n: 3, nome: 'Funghi',    prezzo: 2.90, select: false},
        {n: 4, nome: 'Altri',  prezzo: 2, select: false}
    ];
    
    $scope.totale= function(){
        
        var tot=0;
        var sel = false;

        if ($scope.listino.val) {
            tot+=parseFloat($scope.listino.val);
        }

        if ($scope.basi.b) {
            tot+=parseFloat($scope.basi.b);
        }

        angular.forEach($scope.ingredienti, function (ingrediente) {
            if (ingrediente.selected) {
                tot += ingrediente.prezzo;
                sel = true;
            }
        });

        $scope.isDisabled = ($scope.paste.p || $scope.listino.val || $scope.basi.b || sel) ? false : true;

        return tot;
    };
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<button ng-click="$scope.ordine()" type="button" class="bottone btn btn-danger" ng-disabled="$scope.isDisabled">
                             Totale da pagare {{$scope.totale()}}€</button>

0 个答案:

没有答案