大家好,,
我有一个小问题,谁能写一些使用编译函数的简单示例,并在指令中作一些解释?
发布于 2013-12-09 08:31:17
我实际上是写了一篇关于这个的博客文章。
它深入到更多关于它是如何工作的细节..。但基本上,它是这样使用的:
// take some HTML
var html = '<div><h2>Some HTML</h2><p ng-repeat="item in items">{{item.name}}</p></div>';
// wrap it in an element
var element = angular.element(html);
// compile it as a view with $compile
var compiledView = $compile(element);
// create a scope (if you don't already have one)
var $scope = $rootScope.$new();
$scope.items = [
{ name: 'Test Monkey', id: 1 },
{ name: 'Bob Hope', id: 2 }
];
// pass that scope into the compiled view
// to apply that scope to the view
compiledView($scope);
// Now all of your directives are wired up and bound to the scope you passed!
注意:您不应该真的在指令之外使用它。
发布于 2013-12-09 07:57:01
我建议你阅读这系列文章。它准确地显示了你要找的东西。
https://stackoverflow.com/questions/20474838
复制相似问题