我想如果我打ng-controller="GeneralInfoCtrl"了我的DOM中的多个元素,他们会共享相同的$scope(或者至少双向绑定不起作用).
我想这样做的原因是因为我在HTML的不同部分有不同的只读视图和相关的模态对话框,并且它们不共享共同的祖先(除了<body>和<html>).
有没有办法让两个控制器引用相同的对象/ make数据绑定在它们之间工作?
以下是那些坚持看到标记的代码,用Jade编写:
.client-box(ng-controller="GeneralInfoCtrl")
.box-header
.box-title
h5 General Information
.box-buttons
button.btn.btn-small(data-target='#editGeneralInfo', data-toggle='modal', data-backdrop='static') <i class="icon-pencil"></i> Edit
.box-body
table.table.table-tight.table-key-value
tr
th Name
td {{client.fullName()}}
tr
th Also Known As
td {{client.aka}}
tr
th Birth Date
td {{client.birthDate|date:'mediumDate'}}
...
#editGeneralInfo.modal.hide.fade(ng-controller="GeneralInfoCtrl")
.modal-header
button.close(type='button', data-dismiss='modal') ×
h3 Edit General Information
.modal-body
form.form-horizontal.form-condensed
.control-group
label.control-label First Name
.controls
input(type='text', placeholder='First Name', ng-model='client.firstName')
.control-group
label.control-label Last Name
.controls
input(type='text', placeholder='Last Name', ng-model='client.lastName') …Run Code Online (Sandbox Code Playgroud) angularjs ×1