[英]Loading partial with Angular directives not rendering the second time the view is loaded
I am buulding an app using ionic framework. 我正在构建使用离子框架的应用程序。 I wonder this is more of an AngularJS issuse rather than ionic issuse. 我想这更多是AngularJS issuse而不是离子issuse。
I have following states under main abstract app state. 我在主要抽象应用程序状态下具有以下状态。
app.state('app.a', {
url: "/a",
views: {
"mainContent": {
templateUrl: "app/views/a.html"
}
}
}).state('app.b', {
url: "/b",
views: {
"mainContent": {
templateUrl: "app/views/b.html"
}
}
});
I have a directive to load partial as following. 我有一条指令要加载部分如下。
app.directive('widthLengthLoadSpeed', function () {
return {
restrict: 'E',
scope: {
id: '=id'
},
scope: true,
templateUrl: 'app/views/partials/width.length.load.speed.htm.html'
}
})
On a.html I have a button which has ng-click to a function which has following code. 在a.html上,我有一个按钮,可以按ng键单击具有以下代码的函数。
angular
.element(document
.getElementsByClassName("widthLengthLoadSpeedBeforethis"))
.prepend(
$compile('<width-length-load-speed id="StraightRunning_'+$scope.$id+'">
</width-length-load-speed>')($scope));
if ($scope.$root.$$phase != '$apply' &&
$scope.$root.$$phase != '$digest') {
$scope.$apply();
and on b.html the button is linked to function with the code. 在b.html上,该按钮与代码链接在一起以起作用。
angular
.element(document
.getElementsByClassName("widthLengthLoadSpeedBeforethis"))
.prepend(
$compile('<width-length-load-speed id="circular_'+$scope.$id+'">
</width-length-load-speed>')($scope));
if ($scope.$root.$$phase != '$apply' &&
$scope.$root.$$phase != '$digest') {
$scope.$apply();
The views are loaded correctly with partials when I click the button on a.html and go to b.html and viceversa. 当我单击a.html上的按钮并转到b.html时,视图将正确地加载了局部视图。 However, the view doesn't load the partial when I go back and click button on one the pages that I have already been after being on another page. 但是,当我返回另一页面后已经单击的页面上的按钮时,该视图不会加载部分视图。 I can see the html in the element though while debugging. 我可以在调试时在元素中看到html。 I am banging on the this the whole day. 我整天都在敲这个。 Any help with be appreciated. 任何帮助,不胜感激。
Your views are conflicting each other due to caching. 由于缓存,您的视图彼此冲突。
Disable cache with an attribute cache-view = false
. 使用属性cache-view = false
禁用缓存 。
<ion-view cache-view="false" view-title="My Title!">
...
</ion-view>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.