Angular,加载已编译的模板

时间:2014-12-17 13:01:30

标签: angularjs

是否有任何方法可以通过角度模板编译$compile或加载,例如。

模板:

<div ng-app="app" class="ng-scope" dynamic>
  <div ng-controller="TestCtrl" class="ng-scope">
    <!-- ngRepeat: i in items -->
    <div ng-repeat="i in items" class="ng-scope ng-binding">learn angular</div>
    <!-- end ngRepeat: i in items -->
  </div>
</div>

代码:

var app = angular.module('app', []);

app.directive('dynamic', function ($compile) {
 return {
   restrict: 'A',
   replace: true,
   link: function (scope, ele, attrs) {
     // what may be there?
   }
  };
});

function TestCtrl($scope) {
 // got "TypeError: Cannot read property 'push' of undefined"
 $scope.items.push({title:'learn force'});
}

用例: 某些内容可能会在后端预呈现。

0 个答案:

没有答案