Angularjs 如何为ng模型定义赋值

Angularjs 如何为ng模型定义赋值,angularjs,angularjs-directive,angularjs-scope,angular-ui,angular-ui-bootstrap,Angularjs,Angularjs Directive,Angularjs Scope,Angular Ui,Angular Ui Bootstrap,我正在应用程序中使用typeahead的ui引导 <input type="text" ng-model="newItem.id" class="form-control"> <pre>Model: {{customSelected | json}}</pre> <input type="text" ng-model="customSelected" typeahead="asset as asset.asset_name for asset in as

我正在应用程序中使用typeahead的ui引导

<input type="text" ng-model="newItem.id" class="form-control">
<pre>Model: {{customSelected | json}}</pre>
<input type="text" ng-model="customSelected" typeahead="asset as asset.asset_name for asset in assets | filter:{asset_name:$viewValue}" class="form-control">

如果要将选定的
资产
id
分配给
新项目.id

    function ctrl($scope){
        $scope.assets = [{"id":"1","asset_reg_no":"AST1","asset_name":"Omega Shopping Complex","asset_type_id":"2","description":"Shopping Complex in Calicut","created_on":"2014-01-28 16:03:23","asset_type_name":"Building"},{"id":"2","asset_reg_no":"AST2","asset_name":"Keedam Chicken Farm","asset_type_id":"2","description":"Chicken farm in Valivida","created_on":"2014-01-28 16:04:06","asset_type_name":"Building"}];

    $scope.newItem = {};
    $scope.$watch('customSelected', function(asset, oldAsset){
    $scope.newItem.id = asset.id;
    $scope.newItem.text = asset.asset_name;
      });

    }
如果我理解你,这就是你想要的


这里的问题是,当我选择项目时,文本框显示的是id而不是文本,我希望自动完成的文本会出现在那里。当我选择以前的代码时,我将得到如下结果:
{“id”:“1”,“asset\u reg\u no”:“AST1”,“asset\u name”:“Omega购物中心”,“asset\u type\u id”:“2”,“description”:“Calicut购物中心”、“创建日期”:“2014-01-28 16:03:23”、“资产类型名称”:“Building”}
我想将
id
分配给一个隐藏的文本框,并将
资产注册号
分配给另一个文本。
<input type="text" ng-model="newItem.id" typeahead="asset.id as asset.asset_name for asset in assets | filter:{asset_name:$viewValue}" class="form-control">
    function ctrl($scope){
        $scope.assets = [{"id":"1","asset_reg_no":"AST1","asset_name":"Omega Shopping Complex","asset_type_id":"2","description":"Shopping Complex in Calicut","created_on":"2014-01-28 16:03:23","asset_type_name":"Building"},{"id":"2","asset_reg_no":"AST2","asset_name":"Keedam Chicken Farm","asset_type_id":"2","description":"Chicken farm in Valivida","created_on":"2014-01-28 16:04:06","asset_type_name":"Building"}];

    $scope.newItem = {};
    $scope.$watch('customSelected', function(asset, oldAsset){
    $scope.newItem.id = asset.id;
    $scope.newItem.text = asset.asset_name;
      });

    }