在 快速 的答案可能是:
<div ng-include="'tempTest'"></div>
可能您只是忘记了引用模板的单引号。
在 漫长 的答案:
不建议您访问控制器内部的DOM,因为代码会被
$scope.$apply()调用淹没,您会遇到麻烦。考虑使用指令实现此功能。我试图从这里的代码创建起点
http://plnkr.co/UWUCqWuB9d1dn6Zwy3J3
var app = angular.module('plunker', ['ngAnimate']);app.directive('greeting', function($compile){ return { restrict: 'E', scope: { name: '=' }, template: '<div>'+ ' <span>Hello {{name}}!</span>'+ ' <button ng-click="insert()">test</button>'+ '</div>', link: function(scope, element, attrs) { scope.insert = function() { var container = angular.element('<div ng-include="'tempTest.html'"></div>'); element.before($compile(container)(scope)); } } }})app.controller('MainCtrl', function($scope) { $scope.name = 'World';});<greeting name="name"></greeting>模板元素已插入Hello World!每次单击按钮时为textnode。
旁注 您甚至不需要,
scope{ name:'='}因为该指令将继承其周围的作用域,但是它是将控制器变量显式传递(实际绑定)控制器变量的更简洁的方法。


