2015年12月15日 星期二

angularjs 搭配 asp.net 注意事項

★呼叫 $http.post 若不須帶參數還是要給空值
$http.post('aaa.aspx/aaa', {}).then(function (result) {
                            $scope.users = JSON.parse(result.data.d);                         
                        }, function (response) { });


★若有使用 updatepanel 則為了讓其中的 angularjs 語法正常執行,必須於 controller 中加入一段如下語法
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args) {
                      var elem = angular.element(document.getElementById("UpdatePanelController"));
                    $compile(elem.children())($scope);
                    $scope.$apply();
                });
目的是每次非同步作業執行後必須重新編譯updatepanel 內容
html 範例片段
====
<div ng-app="module1" ng-controller="ctrl1" id="UpdatePanelController">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource預約紀錄" DataKeyNames="id" OnItemDataBound="ListView1_ItemDataBound">
<ItemTemplate>
<tr>
<td>
<input type="checkbox" ng-click='<%# "register("+Eval("id")+")" %>' />
注意: 無法使用 ng-change,會造成 $compile 出現錯誤訊息

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...