【发布时间】:2014-10-27 16:58:32
【问题描述】:
我在使用 .Net 部分回发时遇到了麻烦。
问题与此基本相同:Re-initialize Angular bindings after partial postback
基本上我有一个选项卡,上面有 angular 应用程序,然后我有第二个选项卡和一些 c# 控件,我必须在选项卡之间进行部分回发,当我返回我的应用程序时,什么都没有。
我尝试使用 ngView 进行路由,然后我尝试了$route.reload()(它进入控制器,我可以看到模板正在被拉下,但页面上的结果是无)。然后我尝试了compile(templateCache.get(lazyTableControllerRoute.current.templateUrl))(scope) 提到的here。什么都没有。
请帮忙:)
每次回发后,我都会将这个 html 放在页面上:
LiteralControl lazyControl = new LiteralControl("<div ng-app=\"LazyLoadingApp\" style=\"padding:10px\" ng-controller=\"LazyTableController\" ng-view><lazy-table> </lazy-table></div>");
Controls.Add(lazyControl);
还有一些配置常量,例如templateUrl。
这是我的代码:
var app = angular.module('LazyLoadingApp', ['ui.bootstrap', 'ngRoute'], function ($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
});
app.config(function ($routeProvider, $locationProvider, tableTemplateUrl) {
$routeProvider.when('/Page.Web.UI/sptl_project.aspx', {
controller: 'LazyTableController',
templateUrl: tableTemplateUrl,
});
// configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(true);
});
//**This objects I am using after partial postback to check in the console if e.g. $route.reload() works..**
var lazyTableControllerRoute = null;
var templateCache = null;
var compile = null;
var scope = null;
app.directive('lazyTable', ['tableTemplateUrl',
function (tableTemplateUrl) {
return {
name: 'lazyTable',
priority: 0,
restrict: 'E', // E = Element, A = Attribute, C = Class, M = Comment
templateUrl: tableTemplateUrl
};
}
]).controller('LazyTableController', ['$scope', '$rootScope', 'lazyFactory', 'opsPerRequest', 'header', '$route', '$templateCache', '$compile',
function ($scope, $rootScope, lazyFactory, opsPerRequest, header, $route, $templateCache, $compile) {
lazyTableControllerRoute = $route;
var loadingPromise = null;
templateCache = $templateCache;
compile = $compile;
scope = $scope;
(...) rest is not important
更新:
我正在尝试使用 require.js..(同样,它在整个页面加载后工作。)我的想法是在部分回发后引导元素。 我构建了简单的测试用例,在更新面板和我的应用程序中有一个简单的按钮,只是进行部分回发。单击后(当应用程序消失时)我在控制台中尝试:
angular.bootstrap(document, ['LazyLoadingApp'])
然后我得到了我无法删除的错误:
App Already Bootstrapped with this Element 'document'
这里是 plunker 用于 require.js 方式的应用程序(但请记住,这仅用于代码审查目的..)
【问题讨论】:
标签: c# javascript asp.net angularjs partial-postback