我有一个标准的应用程序:
angular.module('angularFrontApp', [
'ngRoute',
'ngResource',
'ngAnimate'
]).config(AppConfig);
和一些控制器
angular.module('angularFrontApp')
.controller('formsController', formsController);
formsController.$inject = ['$scope', 'AjaxForms', 'appConst'];
function formsController ($scope, AjaxForms, appConst) {
//.....
}
我正在尝试在 ng-include 中调用控制器,但它在动态模板中失败(它的动态变量像一些.html):
<div ng-include="dynamicTemplate"></div>
<div ng-controller="formsController">some stuff....</div>
但是如果我在包含之外调用控制器 - 它工作正常。为什么 angular 看不到包含中的控制器和其他内容?
因为你的ng-include是错误的:ng-include需要一个表达式而不是一个字符串。
<div ng-include="'some.html'"></div>