Javascript 页面不可滚动,ng include=";函数()代码不再使用了 重要编辑
问题不会发生在Javascript 页面不可滚动,ng include=";函数()代码不再使用了 重要编辑,javascript,html,angularjs,internet-explorer,Javascript,Html,Angularjs,Internet Explorer,问题不会发生在ng hide中,我们删除了引导折叠的代码,但它仍然会发生。我的下一个猜测是下面的代码 <div ng-include="getTemplateUrl()"></div> $routescope上的属性用于为每个HTTP请求显示一个简单的进度条。您的代码中有许多奇怪的地方$scope.watch当第一个函数返回的结果与上次执行的结果不同时,将执行回调。你肯定不会用你所拥有的获得预期的行为:相反,只需观察model.key 另一个问题是重新定义getTemp
ng hide
中,我们删除了引导折叠的代码,但它仍然会发生。我的下一个猜测是下面的代码
<div ng-include="getTemplateUrl()"></div>
$routescope
上的属性用于为每个HTTP请求显示一个简单的进度条。您的代码中有许多奇怪的地方<代码>$scope.watch当第一个函数返回的结果与上次执行的结果不同时,将执行回调。你肯定不会用你所拥有的获得预期的行为:相反,只需观察model.key
另一个问题是重新定义getTemplateUrl
的方式:不应该重新定义函数,而应该更改它返回的内容,正如@New Dev在注释中指出的那样
固定指令:
stuffModule.directive('stuffDirective', function ($compile) {
var oldId = undefined;
return {
restrict: 'E',
scope: {
model: '='
},
link: function (scope, elem, attrs) {
scope.$watch(function (scope) {
if (oldId !== scope.model.key) {
oldId = scope.model.key;
return true;
}
return false;
}, function (newValue, oldValue) {
if (scope.model.someswitch) {
switch (scope.model.someswitch) {
case 'condition1':
scope.getTemplateUrl = function () {
return 'condition1.html';
}
break;
case 'condition2':
case 'condition3':
scope.getTemplateUrl = function () {
return 'condition23.html';
}
break;
default:
break;
}
} else {
scope.getTemplateUrl = function () {
return 'default.html';
}
}
});
},
template: '<div ng-include="getTemplateUrl()"></div>'
};
});
link: function (scope, elem, attrs) {
// Or simply bind templateUrl in your ng-include
scope.getTemplateUrl = function() {
return scope.templateUrl;
}
scope.$watch('model.key', function (newValue) {
if (scope.model.someswitch) {
switch (scope.model.someswitch) {
case 'condition1':
scope.templateUrl = 'condition1.html';
break;
case 'condition2':
case 'condition3':
scope.templateUrl = 'condition23.html';
break;
default:
break;
}
} else {
scope.templateUrl = 'default.html';
}
});
}
现在你的滚动问题可能与此无关。如果模板是正确的,但是滚动错误,那么您应该调查是什么导致了该特定问题。为了让我们提供帮助,我们需要一种重现或理解问题的方法。这可能与您的ng有关,包括在您的手表触发之前保持空状态。您可以尝试使用ng if,因为只有当ng if表达式为true时,才会在DOM中包含您的元素
template: '<div ng-if="!whatever you had in your ng-hide" ng-include="getTemplateUrl()"></div>'
模板:“”
我找到了解决方案,它与ng include
没有任何关系。问题是,我们使用了一个引导模式,我们是这样打开的:
$('#modal').modal('show');
但是它没有正确隐藏,结果是主体保持类模态打开
,这导致滚动不再工作
感谢所有帮助和投入时间的人。您能展示相关代码吗?只是ajax请求pls@AngularLover添加了一些代码。这有点奇怪,可能您必须使用$observe或$watch。May在IE中,digestCycle工作不正常。@AngularLover“ypu可能必须使用$observe或$watch”是什么意思?您能否显示您实际将值分配给ng hide的代码?
$('#modal').modal('show');