我在使用 .Net 部分回发时遇到了问题。
问题与此基本相同:Re-initialize Angular bindings after partial postback
基本上我有一个选项卡,上面有 Angular 应用程序,然后我有第二个选项卡和一些 c# 控件,我必须在选项卡之间进行部分回发,当我返回我的应用程序时,什么也没有。
我尝试过使用 ngView 进行路由,然后我尝试了 $route.reload()
(它转到 Controller ,我可以看到模板正在被拉下,但页面上的结果是没有任何)。然后我尝试了 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 方式为应用程序(但请记住,这只是为了代码审查目的..)
最佳答案
- 不要同时使用 ng-app 和 angular.bootstrap。
- 你有没有编译“ng-app”,如果没有。
关于c# - Angular 模板和 .NET 部分回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25640138/