我在 app.js 中定义了不同的控制器和相应的模板 url:
var App = angular.module('FormApp', [ 'ngRoute','ui.bootstrap', 'dialogs', 'oc.modal' ]);
App.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/addClient', {
templateUrl : '../../resources/partialHtml/addClientLayout.html',
controller : FormController
}).when('/conflist/:commandName/:client/:env', {
templateUrl : '../../resources/partialHtml/testPrase.html',
controller : TestParseController
}).when('/addNewCommand', {
templateUrl : '../../resources/partialHtml/addNewCommand.html',
controller : AddNewCommandController
})
} ]);
我的 TestParseController 定义如下:
var TestParseController = function($scope, $window, $http, $routeParams, $sce,
$compile) {
$scope.hide = function(obj) {
alert($routeParams.commandName);
};
$scope.to_trusted1 = function(html_code) {
html_code = $sce.trustAsHtml(html_code);
$scope.content = html_code;
alert(html_code);
$compile( document.getElementById('innerh'))($scope);
};
$http.get('client/getConfList/' + $routeParams.commandName)
.success(
function(data) {
$scope.html_content = "<button data-ng-click='hide($event)'>Click me!</button>";
$scope.to_trusted1($scope.html_content);
});
}
html:testParse.html:
<h3 data-ng-click="hide($event)" class="plus">Add</h3>
<div ng-bind-html="content" id="innerh"> </div>
div 得到正确填充,但 ng-click 填充按钮不起作用,但它适用于页面本身可用的 h3 标签。
有人请帮忙..