对我来说,我试图从回调(在另一个窗口中)访问/设置角度的值;解决方案是使用 jQuery 的data
方法。data
API 允许您将对象文字附加到 DOM 节点。因此,我没有使用诸如全局变量之类的东西(这也可以),而是执行以下操作:
/**
* Listen to a global "lookupTemplate" event
*/
$j(document).on("lookupTemplate", function(event, template) {
$j(document).data("template", template);
window.open("/callbackURL", 'Callback Window', 'status=0,toolbar=0,height=230,width=358');
});
/**
* Callback from other window, to change template ID and name (it's global)
* @param {String} template_id the ID for the selected template from the other window
* @param {String} template_name the name for the selected template from the other window
*/
function templateChosen(template_id, template_name) {
var template = $(document).data("template");
var appendedSelector = "[" + template.index + "]";
$('[name="templateId' + appendedSelector + '"').val(template_id);
$('[name="templateName' + appendedSelector + '"').val(template_name);
// Update angular vars just in case
template.id = template_id;
template.name = template_name;
}
var app = angular.module("app", []).controller("ActionsController", function($scope) {
$scope.actions = [];
$scope.lookupTemplate = function(index) {
$scope.actions[index].template.index = index;
$(document).trigger("lookupTemplate", $scope.actions[index].template);
}
}
);
我使用 Angular 中包含的helper增加name
每个 new 的属性。action
{{index}}