Angularjs如何返回多变量

时间:2014-05-05 05:36:57

标签: angularjs model

开始学习angularjs我正在尝试一些简单的例子。 我想在我看来2个变量total1 en total2,它们是在我的js中的函数中计算的。

我的js

    var total1 = 0;
    var total2 = 0; 

    // Use the angular forEach helper method to
    // loop through the services array:

    angular.forEach($scope.services, function(s){
        if (s.active){
            total1+= s.price;
            total2+= 1;
        }
    });

    return [total1, total2];
};

我的HTML

        <div class="total">

            <!-- Calculate the total price of all chosen services. Format it as currency. -->
            Totaal: <span>{{total1 | currency:"€ "}}</span>
            Selected: <span>{{total2 | currency:"€ "}}</span>
        </div>

是否可以使用像{{my_var1}} {{my_var2}}

这样的某些方式在视图中显示角度变量

1 个答案:

答案 0 :(得分:1)

您只需将变量公开为范围中的字段。

$scope.total1 = 0;
$scope.total2 = 0; 

这应该足够了,不需要返回任何东西。