我已经定义了一个类,将其设置为instante并将该对象归属于范围。 ng-model中的引用已经完成,但我不知道为什么这段代码不起作用。帮我 我怀疑Angular不适用于使用保留字'class'
定义的类-- app.js
angular.module('myApp', [
'myApp.controllers'
]);
-- controllers.js
class Finance() {
constructor() {
this.salary = 100;
this.percentage = 10;
}
result() {
return this.salary * this.percentage * 0.01;
}
}
var m = angular.module('myApp.controllers', []);
m.controller('FinanceController', function($scope) {
$scope.f = new Finance();
console.log($scope.f.salary);
console.log($scope.f.percentage);
console.log($scope.result());
});
-- index.html
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<title>Finance Meter</title>
</head>
<body ng-controller="FinanceController">
Your Salary?
<input type="text" ng-model="f.salary">
<br/>How much should you invest in shopping?
<input type="text" ng-model="f.percentage"> %
<br/>The amount to be spent on gadgets will be: <span>{{f.result()}}</span>
<script src="lib/angular/angular.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
</body>
</html>
答案 0 :(得分:0)
出现语法错误:
的console.log($ scope.f.result());