我正在根据国家/地区选择实施不同的地址表单(如here所述)。
是否有任何广泛使用的指令或插件用于使用Angular进行显示?比仅使用<ng-if>
块更优雅的东西?当我环顾四周时,我找不到多少,所以我想知道是否有人有任何漂亮的解决方案。
答案 0 :(得分:1)
一种方法是创建几个模板,每个不同类型的地图一个,并有一个地图将它们映射到选定的国家。
请参阅plunkr作为示例here
<body ng-controller="MainCtrl">
<select ng-model="selected" ng-options="c as c for c in countries"></select>
<div ng-include="templates[selected] || 'default' "></span>
</body>
<script type="text/ng-template" id="US">
<input type="text">
</script>
<script type="text/ng-template" id="UK">
<input type="text">
<input type="text">
</script>
<script type="text/ng-template" id="default">
Unknown Country
</script>
控制器:
app.controller('MainCtrl', function($scope) {
$scope.templates = {
UK: "UK",
US: "US"
};
$scope.countries = [ "UK", "US", "AR" ];
});