简体   繁体   中英

Input and Output (using angular)

I don't understand why it's displaying the function within the input field? Im simply trying to enter a name and display it back to the user.

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;
    }
};
});

Because you are using a function as model for a two ways data binding. Input element will assign a string to fullName when the binding is from view to scope

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM