Angular JS:数据绑定在Date中不起作用

时间:2022-06-18 19:45:27

I am using ui-date of Angular JS. There are multiple dates which are getting rendered with the loop.Below is my HTML code.

我正在使用Angular JS的ui-date。有多个日期通过循环呈现.Below是我的HTML代码。

<tr  ng-repeat="(k,v) in :: vm.dateMap">
 <th>
<input ng-attr-id="{{ 'dateCmp-' + k}}" ui-date="vm.dateOptionMap[k]">
</th>
</tr>

In my controller, dateOptionMap contains below value

在我的控制器中,dateOptionMap包含以下值

          vm.dateOptionMap = {};
            vm.dateOptionMap['03/06/2014'] = {
                changeYear: true,
                changeMonth: true,
                dateFormat: 'dd-mm-yy'
            };
            vm.dateOptionMap['07/21/2016'] = {
                changeYear: true,
                changeMonth: true,
                dateFormat: 'dd-mm-yy'
            };
            vm.dateOptionMap['09/06/2017'] = {
                changeYear: true,
                changeMonth: true,
                dateFormat: 'dd-mm-yy'
            };

On clicking of a button i am changing map value with the below one.

点击一个按钮我正在用下面的一个改变地图值。

        vm.dateOptionMap['03/06/2014'] = {
                    changeYear: false,
                    changeMonth: false,
                    dateFormat: 'dd-mm-yy'
                };

How ever this change is not getting reflected on UI. Can you please help me with this ?

这种变化怎么没有在UI上反映出来。你能帮我解决这个问题吗?

1 个解决方案

#1


0  

This line ng-attr-id="{{ 'dateCmp-' + k}}" only renders a value to the id attribute. ng-attr-id DOES NOT BIND the values.

此行ng-attr-id =“{{'dateCmp-'+ k}}”仅向id属性呈现值。 ng-attr-id不绑定值。

To Bind your date values to <input>, you should set appropriate js variable in ng-model attribute and then change the value of variable dynamically.

要将日期值绑定到,应在ng-model属性中设置适当的js变量,然后动态更改变量的值。

#1


0  

This line ng-attr-id="{{ 'dateCmp-' + k}}" only renders a value to the id attribute. ng-attr-id DOES NOT BIND the values.

此行ng-attr-id =“{{'dateCmp-'+ k}}”仅向id属性呈现值。 ng-attr-id不绑定值。

To Bind your date values to <input>, you should set appropriate js variable in ng-model attribute and then change the value of variable dynamically.

要将日期值绑定到,应在ng-model属性中设置适当的js变量,然后动态更改变量的值。