我将不胜感激任何帮助。我的问题:我无法在我的 View 中显示 $scope.info
的值。我无法直接访问html,所以我只能通过js更改DOM。
我创建了新元素并使用 append()
方法将其添加到 DOM
$scope.info = {
clicks: 15862,
spent: '$124',
created: '04/08/2017',
author: 'John Kovalenko',
name: 'Advertise US'
};
var info = document.createElement('div');
info = angular.element(info).attr({
'ng-bind': 'info',
'class': 'statistic-info'
});
angular.element(infoContainer).append(info[0]);
我在这里创建了示例。 http://jsfiddle.net/ADukg/13598/
我做错了什么?谢谢
最佳答案
当您手动注入(inject)任何使用指令的内容时,您必须使用 $compile
var info = angular.element('<div>').attr({
'ng-bind': 'info.author',
'class': 'statistic-info'
});
info = $compile(info)($scope);
angular.element(infoContainer).append(info);
无论你使用什么地方,一定要注入(inject)$compile
关于javascript - 如何在使用append()方法添加的html元素中显示 Controller 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45460300/