我有角度模板,有一个div。我试图基于$ watch将html视图(.html)页面加载到div。但是,它永远不会将html视图加载到div。这是我的控制器,我只发布加载html视图的代码部分。
var filtertemplate = "#locationChart_right";
$scope.templateUrl = '/_layouts/AngularControls/MyController/Views/MyChart.html';
$scope.$watch("currentItem", function () {
$scope.currentConfig = $rootScope.currentItem;
LocDetailsChartService.getUserPrefs()
.then(function (response) {
var data = response.data.ChartsUserPrefs;
$scope.MeritType = data.MeritType;
if ($scope.MeritType !== undefined) {
if ($scope.MeritType == "Score") {
$(filtertemplate).load("/_layouts/AngularControls/MyController/Views/MyScoreChart.html");
}
if ($scope.MeritType == "Potential") {
$(filtertemplate).load("/_layouts/AngularControls/MyController/Views/MyPercentChart.html");
}
}
// $scope.radioButtonHandler($scope.MeritType);
});
});
这是我的HTML。
<div class="locationChart_container">
<div class="locationChart_left">
</div>
<div class="locationChart_right">
</div>
有人可以告诉我我在做错的地方,如果有可能的话请告诉我是否有这样做的角色。
答案 0 :(得分:1)
您需要添加$ scope。$ apply()或者注入$ timeout并将其添加到代码中以通知您的更改角度
var filtertemplate = "#locationChart_right";
$scope.templateUrl = '/_layouts/AngularControls/MyController/Views/MyChart.html';
$scope.$watch("currentItem", function () {
$scope.currentConfig = $rootScope.currentItem;
LocDetailsChartService.getUserPrefs()
.then(function (response) {
var data = response.data.ChartsUserPrefs;
$scope.MeritType = data.MeritType;
if ($scope.MeritType !== undefined) {
if ($scope.MeritType == "Score") {
$(filtertemplate).load("/_layouts/AngularControls/MyController/Views/MyScoreChart.html");
$scope.$apply()
}
if ($scope.MeritType == "Potential") {
$(filtertemplate).load("/_layouts/AngularControls/MyController/Views/MyPercentChart.html");
$scope.$apply()
}
}
// $scope.radioButtonHandler($scope.MeritType);
});
});