1
AngularJSの学習に関する本のコード例を説明していますが、本の説明どおりに動作しないものがあります。 ChromeとFirefoxの両方でhtmlページを開くと、最後のものまで角度式に問題はありません。その最後の口ひげを得て、正しいものを見せるためのアイデアは何ですか?AngularJSとJS Math.max.apply()が連携していません
angular.module('myApp', [])
.controller('myController', function($scope) {
$scope.Math = window.Math;
$scope.myArr = [];
$scope.removedArr = [];
});
<!doctype html>
<html ng-app="myApp">
<head>
<title>AngularJS Expressions</title>
<style>
a{color: blue; text-decoration: underline; cursor: pointer}
</style>
</head>
<body>
<div ng-controller="myController">
<h1>Expressions</h1>
Array:<br>
{{myArr}}<hr>
Elements removed from array:<br>
{{removedArr}}<hr>
<a ng-click="myArr.push(Math.floor(Math.random()*100 + 1))">
Click to append a value to the array</a><hr>
<a ng-click="removedArr.push(myArr.shift())">
Click to remove the first value from the array</a><hr>
Size of Array:<br>
{{myArr.length}}<hr>
Max number removed from the array:<br>
{{Math.max.apply(Math, removedArr)}}<hr>
\t </div>
<script src="http://code.angularjs.org/1.3.0/angular.min.js"></script>
<script src="js/expressions_javascript.js"></script>
</body>
</html>
あなたは直接interpolation' 'から関数を呼び出す行い、' $ scope.Math = Math'内のコントローラヘクタールない限り、スコープに 'Math'オブジェクトのメソッドにアクセスすることはできません{{}}、そして 'Math。* 'の計算はコントローラ側で行います。 '{{calculate {removedArr}}}' –
のように{{Math.max.apply(...)}}を{{Math.max(1,2,3)}}に変更するとうまくいきます。だから私はあなたがこの状況に当てはまるとは言い切れない。 – waterprincess
ビューにその種のロジックを入れないでください...コントローラに属しています – charlietfl