search

Home  >  Q&A  >  body text

angular.js - angularjs 新人求指导,前台页面上的ng-model如何绑定?

数据模型是这样的:

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

前台对应的声音故障类型,屏幕故障数量,屏幕故障类型这三个输入项用ng-model要怎么绑定?
控制器里这么写可以吗?

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

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