【问题标题】:angularJS update inline script with modelangularJS 用模型更新内联脚本
【发布时间】:2017-01-02 10:01:06
【问题描述】:

我需要更新ng-repeat 中的datetimepicker[i] 脚本,但我不知道该怎么做。

<div class='input-group date' id='datetimepicker{{$index+1}}'>

工作成功并列出

<div class='input-group date' id='datetimepicker1'>

<div class='input-group date' id='datetimepicker2'>

但问题是脚本没有从模型数据更新

$('#datetimepicker{{$index+1}}').datetimepicker();

结果是

$('#datetimepicker{{$index+1}}').datetimepicker();

我想把'#datetimepicker{{$index+1}}'改成'#datetimepicker1'

<tr data-ng-repeat="row in game.result">
    <td>{{$index+1}}</td>
    <td ng-bind="row.host"></td>
    @*<td>
            <input class="form-control text-center" data-ng-model="row.dateStart" />
        </td>*@
    <td ng-controller="DatepickerDemoCtrl">
        <div class="input-group w-360">
            <div class='input-group date' id='datetimepicker{{$index+1}}'>
                <input data-format="yyyy/MM/dd hh:mm:ss" ng-model="row.dateStart" type='text' class="form-control" ng-required="true" />
                <span class="input-group-addon">
                    <span class="fa fa-calendar"></span>
                </span>
            </div>
             <script type="text/javascript">
                $(function () {
                    $('#datetimepicker{{$index+1}}').datetimepicker();
                          });
            </script>
        </div>
    </td>
    <td>
        <select ng-model="row.gameState"
                ng-options="c.Value as c.Text for c in game.states" class="form-control" required></select>
    </td>
    <td>
        <input class="form-control text-center" data-ng-model="row.hostGoals" type="number" required />
    </td>
    <td>
        <input class="form-control text-center" data-ng-model="row.guestGoals" type="number" required />
    </td>
    <td ng-bind="row.guest"></td>
</tr>

更新

我将代码移动到控制器中并在控制器中制作 html

控制器 - MVC

onlineResult.dateHtml = @"<script type=""text/javascript"">$(function () {$('#datetimepicker"+(i + 1).ToString()+ "').datetimepicker({format: 'YYYY/MM/DD HH:mm:ss'});});</script>";

并将视图更新为

<p compile data-ng-bind-html="to_trusted(row.dateHtml)"></p>

我的新问题是Get 中的模型绑定,但Post 中没有更改。 当我提交表单时,我的 Get 发送到控制器的数据未更改

【问题讨论】:

  • 整个方法不起作用....这需要在自定义指令中完成。你很可能会发现这个日期选择器的角度模块已经可用
  • 不要将脚本标签放在角度模板中......它们会被剥离并且不会执行
  • ng-controller="DatepickerDemoCtrl"&gt;ng-repeat 内。最糟糕的方法。实际上这个模板使用的是哪个控制器?
  • @RameshRajendran 为什么采用最糟糕的方法?
  • @charlietfl 问题已更新

标签: javascript c# html angularjs asp.net-mvc


【解决方案1】:

我使用了 angularjs 指令 datetimepicker

https://material.angularjs.org/latest/demo/datepicker

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    相关资源
    最近更新 更多