2017-05-27 60 views
0

我有这样的代码在我的.aspx和是一个UpdatePanel内有触发事件的onclickC#为什么当我用updatepanel回发时,组件Angularjs消失了?

<div id="componentdt" ng-app="myApp" ng-controller="MyCtrl" class="container" style="width: 100%"> 
<div rm-datepicker ng-model="oDate1" rm-config="rmConfig1"></div> 
<input type="hidden" id="selectedPartnerId" runat="server" ng-value="oDate1 | date: 'dd-MM-yyyy'" /> 
</div> 

,这是我的脚本,我在我的.aspx。

<script> 
     var app = angular.module("myApp", ["rmDatepicker"]); 

     /* Datepicker global configuration */ 
     app.config(["rmDatepickerConfig", function (rmDatepickerConfig) { 
      rmDatepickerConfig.mondayStart = true; 
      rmDatepickerConfig.initState = "month"; 
     }]); 
</script> 

<script> 

    $(document).ready(function() { 

      var app = angular.module("myApp"); 

      var MyCtrl = function ($scope) { 


       var currentDate = new Date(); 
       var date = currentDate.setDate(currentDate.getDate() + 1); 

       /* Datepicker local configuration */ 
       $scope.rmConfig1 = { 
        mondayStart: false, 
        initState: "month", /* decade || year || month */ 
        maxState: null, 
        minState: "month", 
        decadeSize: 12, 
        monthSize: 42, /* "auto" || fixed nr. (35 or 42) */ 
        min: new Date(date), 
        max: new Date('2023-11-21'), 
        format: "yyyy-MM-dd" /* https://docs.angularjs.org/api/ng/filter/date */ 
       }; 

       $scope.rmConfig2 = { format: "d MMM yyyy" }; 

       $scope.oDate1 = new Date(date); 
       $scope.oDate2 = null; 
       $scope.clearInput = function() { 
        $scope.oDate2 = null; 
       } 
      }; 
      app.controller("MyCtrl", ['$scope', MyCtrl]); 

     }()); 

     // Init waves (OPTIONAL) :) 
     // window.onload = Waves.init(); 

</script> 

那么,当我做回发时,这个组件消失了,我不知道为什么。 我从AngularJS和ASP.NET webforms开始

回答

0

不应该在更新面板中使用角度。这个不成立。 Asp.net的Web表单反向模式是将MVC的全部或部分HTML页面发送到服务器,并返回在服务器上生成的HTML,而MVC技术只从服务器请求数据并在客户端呈现它。

您应该了解MVC模式和Web表单如何工作以理解这些技术的概念,否则您将在未来面临更多问题。

要特定于您的问题,请勿使用更新面板下的角度部分。 Angular能够将请求发送到服务器并更新页面的一部分。如果您使用的是Angular,请将Ajax控件留在后面。

相关问题