【发布时间】:2017-07-20 12:57:15
【问题描述】:
如何在UpdatePanel 内的 ASP.Net 中部分回发(来自 ascx 页面)后调用 AngularJS 函数。最初我在ng-init 上调用角度函数。但是在部分回发之后,该函数没有被调用。我怎么能调用这个函数?
函数名称是BindLeadGridHeader。这是我的 Angular JS 代码:
.controller('CtrlSalesNav', ['$scope', '$http', '$location', '$timeout', function ($scope, $http, $location, $timeout) {
//function for Bind Module Name Drop Down Created By :Prashant Kumar OnDate:21.04.2017
var UserId = sessionStorage.CurrentUserId;
var CurrentModuleName = 'Lead';
$scope.AllHeader = '';
//code for bind all header to table
$scope.BindLeadGridHeader = function () {
$http.get(WebApiUrl + "api/GetAllLeadHeader?UserId=" + UserId + "&ModuleName=" + CurrentModuleName).then(function (response) {
alert('Header bind call');
$scope.AllHeader = response.data.Table;
在 UpdatePanel 内的 ascx 页面上调用代码:
<div class="lead_noTopMenu" id="divLeadGrid" ng-controller="CtrlSalesNav" ng-cloak>
<div class="row" style="margin-top: 90px;" data-ng-init="BindLeadGridHeader();">
<!-- Search FORM-->
<div class="row row1" id="search" style="display: none;">
<div class="col-md-12">
<div class="tabbable tabbable-custom">
<ul class="nav nav-tabs">
【问题讨论】:
-
如果您刚刚开始使用此功能,我强烈建议您访问:github.com/johnpapa/angular-styleguide/blob/master/a1/README.md 以获得最佳实践指导。您对 $scope 的使用、缺少数据服务和 ng-init 都是代码异味。这些都是要避免的事情,并且所有事情都会使您在以后迁移到当前版本的 Angular 变得更加困难。说了这么多,你到底想从哪里调用这个函数?
-
我想在部分回发后从 .ascx 页面调用此函数。我厌倦了 angular.element(document.getelementById('divLeadGrid))。 scope().BindLeadGridHeader();但这一个控制台错误范围(...)。 BindLeadGridHeader 不是函数
标签: asp.net angularjs angularjs-ng-init