Javascript 通过ng init将对象传递给ng include
我需要将包含用户信息的对象传递给ng包含模板。该模板预计将用于我目前正在使用的视图之外的更多视图中,因此,我无法使用常规的“ctrlName.user.name”,因为我不知道对象将从哪个控制器提交。这是控制器:Javascript 通过ng init将对象传递给ng include,javascript,angularjs,ng-init,angularjs-ng-include,Javascript,Angularjs,Ng Init,Angularjs Ng Include,我需要将包含用户信息的对象传递给ng包含模板。该模板预计将用于我目前正在使用的视图之外的更多视图中,因此,我无法使用常规的“ctrlName.user.name”,因为我不知道对象将从哪个控制器提交。这是控制器: angular.module('QW').controller('schoolCtrl', function ($state, schoolHandler, userHandler) { var vm = this; vm.activeTemplate; vm.activeTemp
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>
可能问题在于模板中使用了属性
名称
。但是在对象中,user
不是name
的属性。可能问题在于模板中使用了属性name
。但是在对象中,user
不是name
的属性。
<div id="edit-profile-information">
<h5>Förnamn{{user.name}}</h5>
</div>
ng-init="user=school.activeTemplateUser"