如何在ng-repeat上使用on-change

德州697

我正在尝试将2个属性绑定到一个对象。DocumentTypeId,DocumentTypeName。我在选择框中使用了ng-repeat,但无法将其与ng-options配合使用。这种黑客给我带来了问题。我的项目中有ngstorage设置,我可以从$ rootScope获取DocumentTypeName,问题是我无法正确执行该函数.ng-change函数中的参数未定义。我宁愿摆脱黑客,使用ng-options,如果没有的话,我只需要使用它就可以了。开放的建议,谢谢

矮人

 <select class="form-control" ng-model="model.documentTypeId" ng-change="selectDocumentType(docType)">
    <option ng-repeat="docType in docTypes" title="{{docType.DocumentTypeName}}" ng-selected="{{docType.DocumentTypeId == model.DocumentTypeId}}" value="{{docType.DocumentTypeId}}">
        {{docType.DocumentTypeName}}
    </option>
 </select>
奥姆里·阿哈隆(Omri Aharon)

ng-options就像您说的那样,我已经将它与之配合使用,最好是使用它而不是hack。

<select class="form-control" ng-model="model.documentTypeId" ng-change="test()"
         ng-options="docType.DocumentTypeId as docType.DocumentTypeName for docType in docTypes" title="{{docType.DocumentTypeName}}" ng-selected="{{docType.DocumentTypeId == model.DocumentTypeId}}" value="{{docType.DocumentTypeId}}">
            {{docType.DocumentTypeName}}
</select>

并且ng-change仅仅是控制器中的测试功能,因此您可以看到它的工作原理:

$scope.test = function (docType) {
     console.log($scope.model.documentTypeId);
};

工作柱塞

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章