我需要将包含用户信息的对象传递给ng-include模板。该模板预计将用于我目前所使用的视图以外的问题,因此问题,因为我不能使用常规的“ctrlName.user.name”,因为我不知道该对象是从哪个控制器正在添加。这是控制器:
angular.module('QW').controller('schoolCtrl', function ($state, schoolHandler, userHandler) {
var vm = this;
vm.activeTemplate;
vm.activeTemplateUser;
vm.templates = {
'edit-employee' : 'app/templates/edit-profile-modal.html'
}
vm.editEmployee = function(){
// This part should naturally come from database normally
vm.activeTemplateUser = {
firstname : "John",
lastname : "Doe",
email : "John@Doe.com",
phonenumber : "XXXX XXXX XXXX",
profile_pic : "assets/img/profile.png"
}
// Fetches template URL
vm.activeTemplate = vm.templates["edit-employee"];
// Opens modal in which the data is to be inserted
var inst = $('[data-remodal-id=edit-user-modal]').remodal();
inst.open();
}
});
遵循我的include和init:
<div class="remodal" data-remodal-id="edit-user-modal" data-remodal-options="hashTracking: false" id="edit-user-modal">
<div ng-init="user = school.activeTemplateUser" ng-include="school.activeTemplate"></div>
</div>
最后我的模板:
<div id="edit-profile-information">
<h5>Förnamn{{user.name}}</h5>
</div>
简而言之,我希望activeTemplateUser通过设置:
来表示模板内的用户 ng-init="user=school.activeTemplateUser"