Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ng模型中的对象属性_Angularjs_Object_Properties_Ngmodel - Fatal编程技术网

Angularjs ng模型中的对象属性

Angularjs ng模型中的对象属性,angularjs,object,properties,ngmodel,Angularjs,Object,Properties,Ngmodel,我已经定义了一个类,实例化它,并将对象属性化为scope。 ng模型中的引用已经完成,但我不知道为什么这段代码不起作用。帮助我 我怀疑Angular不适用于用保留字“class”定义的类 -- app.js angular.module('myApp', [ 'myApp.controllers' ]); -- controllers.js class Finance() { constructor() { this.salary = 100;

我已经定义了一个类,实例化它,并将对象属性化为scope。 ng模型中的引用已经完成,但我不知道为什么这段代码不起作用。帮助我 我怀疑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>
--app.js
角度.module('myApp'[
“myApp.controllers”
]);
--controllers.js
班级财务(){
构造函数(){
这个工资=100;
这个百分比=10;
}
结果(){
返回this.salary*this.percentage*0.01;
}
}
var m=angular.module('myApp.controllers',[]);
m、 控制器(“财务控制器”,功能($scope){
$scope.f=新金融();
控制台日志($scope.f.salary);
console.log($scope.f.percentage);
log($scope.result());
});
--index.html
财务表
你的薪水?

你应该在购物上投资多少? %
花费在小工具上的金额为:{{f.result()}
出现语法错误:


log($scope.f.result())

出现语法错误:


log($scope.f.result())

您可以使用以下内容定义控制器:
m.controller('Finance',Finance)
(控制器的任何注入都会进入构造函数内部)可能是一个输入错误,但不应该是$scope.f.result()?您可以使用以下内容定义控制器:
m.controller('Finance',Finance)
(控制器的任何注入都会进入构造函数内部)可能是一个输入错误,但不应该是$scope.f.result()?类的正确定义是:没有父类的类金融{..}类的正确定义是:没有父类的类金融{..}