我已将动态控制器添加到我的应用中。我想将JavaScript对象注入该控制器。
动态控制器
function loadEditCommentFABActionbarController($scope, EditCommentFABActionbarObject){
var vm = this;
vm.isOpen = false;
vm.selectedMode = 'md-scale';
vm.selectedDirection = 'down';
vm.postComment = function(){
EditCommentFABActionbarObject.postComment(); // EditCommentFABActionbarObject is a javascript object
};
vm.deleteComment = function(){
EditCommentFABActionbarObject.deleteComment(); // EditCommentFABActionbarObject is a javascript object
};
}
将控制器添加到模块
var app = angular.module('ThinkshopAPP');
app.value("EditCommentFABActionbarObject", this); // this is javascript object, i want to inject into cotroller.
app.controller('EditCommentFABActionbarController', ['$scope', 'EditCommentFABActionbarObject', loadEditCommentFABActionbarController]);
动态添加控制器的Javascript函数
function addController(elementClass, objectName){
var element = $("."+elementClass);
// Compile controller 2 html
var mController = angular.element(document.getElementById("ThinkshopApp"));
mController.scope().activateView(element, objectName);
}
家长控制器
function loadThinkshopApplicationController($scope, $compile){
$scope.activateView = function(element, objectName) {
$compile(element.contents())($scope);
$scope.$apply();
};
}