【发布时间】:2015-09-04 07:19:25
【问题描述】:
在母版页中 n-bind-html 正在工作,但是在调用视图页面时没有得到任何数据。
ng-bind-html="home.title" 正在索引标题 div 中工作。
index.html
....
<title ng-bind-html="home.title"></title>
....
<ng-view></ng-view>
contact.html 但 ng-view 联系页面 ng-bind-html="home.title" 不起作用,{{contact.info}} 不起作用。
<h4 ng-bind-html="home.title"></h4>
<p>{{contact.info}}</p>
控制器:
$scope.trustedHtml = function (plainText) {
return $sce.trustAsHtml(plainText);
}
$http.get('admin/api/?s=getAbout&lang='+lang).success(
function(r){
$scope.about = r.text;
//$scope.about = r.email;
}
);
$http.get('admin/api/?s=getContact'+lang).success(
function(r){
$scope.contact = r;
//$scope.contacttext.infoH = r[0].infoH;
//$scope.contact.infoH = $sce.trustAsHtml(r.infoH);
}
);
$http.get('admin/api/?s=getHome&lang='+lang).success(
function(r){
$scope.home = r;
$scope.home.address = $sce.trustAsHtml(r.address);
$scope.home.phone = $sce.trustAsHtml(r.phone);
$scope.home.email = $sce.trustAsHtml(r.email);
$scope.home.title = $sce.trustAsHtml(r.title);
}
);
关于 about 的 ng-view 页面正在运行。 about.html
<div class="container" style="font-size:16px;" ng-bind-html="trustedHtml(about)"></div>
【问题讨论】:
-
后控制器代码,路由有不同的作用域,如果home.title在页面作用域内对路由作用域是不可见的
标签: angularjs