【问题标题】:Input and Output (using angular)输入和输出(使用角度)
【发布时间】:2018-09-10 09:21:55
【问题描述】:

我不明白为什么它会在输入字段中显示函数?我只是想输入一个名称并将其显示给用户。

HTML:

<div ng-app = "mainApp" ng-controller = 
"studentController">

<tr>
<td>Enter full name:</td>
<td><input type = "text" ng-model = 
"student.fullName"></td>
</tr>



<tr>
<td>Name in Upper Case:</td>
<td>{{student.fullName() | uppercase}}</td>
</tr>

</div>

JAVASCRIPT:

var mainApp = angular.module("mainApp", []);

mainApp.controller('studentController', 
function($scope) {

"use strict";

$scope.student = {

fullName: function() {

    var studentObject;
    studentObject = $scope.student;
    return studentObject.fullName;
    }
};
});

【问题讨论】:

  • 因为你已经用你的 fullName 函数覆盖了你的学生对象的属性 fullName。

标签: javascript html angularjs input output


【解决方案1】:

因为您使用函数作为模型来进行两种方式的数据绑定。当绑定是从视图到作用域时,输入元素将为 fullName 分配一个字符串

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-01
    • 2016-07-02
    • 1970-01-01
    • 2023-01-19
    • 2021-10-04
    • 1970-01-01
    • 2016-11-04
    • 2017-05-12
    相关资源
    最近更新 更多