search

Home  >  Q&A  >  body text

angular.js - A newbie in angularjs, please give me some guidance. How to bind the ng-model on the front page?

The data model is like this:

"audio": {
    "faultType": "string" //声音故障类型
},
"screen":{
    "number": "string" //屏幕故障数量
    "faultType": "string" //屏幕故障类型
}

How to bind the three input items corresponding to the front desk sound fault type, screen fault number, and screen fault type using ng-model?
Is it okay to write this in the controller?

$scope.data = {
    lineNo:$scope.lineNo,
    trainNo:$scope.trainNo,
    createdAt:$scope.createdAt,
    audio: {
      faultType:$scope.fault,
    },
    screen:{
      number:$scope.number,
      faultType:$scope.faultType,
    }
}
大家讲道理大家讲道理2796 days ago742

reply all(2)I'll reply

  • 某草草

    某草草2017-05-15 17:13:27

    <input type="text" ng-model="data.audio"/>

    You can write it like this in js.

    You put
    var data = [
    "audio": {

    "faultType": "string" //声音故障类型
    },

    "screen":{

    "number": "string" //屏幕故障数量
    "faultType": "string" //屏幕故障类型

    }];
    json.parse(data);

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 17:13:27

    controller:

    $scope.model={
            "audio": {
                "faultType": "type1" //声音故障类型
            },
            "screen":{
                "number": 2 //屏幕故障数量
                "faultType": "type2" //屏幕故障类型
            }
        }

    HTML:

    <p>声音故障类型:{{model.audio.faultType}}</p>
    <input type='text' ng-model="model.audio.faultType">
    <p>屏幕故障数量:{{model.screen.number}}</p>
    <input type='number' ng-model="model.screen.number">
    <p>屏幕故障类型:{{model.screen.faultType}}</p>
    <input type='text' ng-model="model.screen.faultType">

    More than

    reply
    0
  • Cancelreply