你好,我是,我怎麼可以綁定不同的數據相同的指令,從同一個對象結合數據
(function() {
'use strict';
angular.module('app', [])
.controller('appController', appController)
.directive('userForm', userForm);
/**@Injectable*/
function appController($http) {
let vm = this;
vm.user = {
userName: 'Test User',
email: '[email protected]',
number: '1456',
address: 'zyz',
state: 'abcd',
city: 'xyz'
};
}
function userForm() {
return {
restrict: 'E',
scope: {
data:'='
},
templateUrl: 'public/app/form.directive.html',
controller: 'appController',
link: function (scope, attr, element) {
}
}
}
})();
<legend>{{headerLabel}}</legend>
<div class="form-group">
<label class="col-sm-3 control-label" for="textinput">{{label1.label1}}</label>
<div class="col-sm-9">
<input type="text" ng-model="data.userName" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="textinput">{{label2}}</label>
<div class="col-sm-9">
<input type="text" class="form-control" ng-model="email">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="textinput">{{label3}}</label>
<div class="col-sm-9">
<input type="text" class="form-control" ng-model="number">
</div>
</div>
<!--Main Index -->
<user-form data="vm.user"></user-form>
<user-form data="vm.user"></user-form>
在這裏,我已經使用相同有點困惑指令兩次,我想綁定第一個指令與個人信息,如用戶名,電子郵件和第二指令應綁定地址info.Is有可能做到這一點?
我想這樣做,因爲實際上它只是演示,我在其中包含答案的描述,答案圖像的對象,用預覽和編輯器問題描述和問題文本,所以我不想爲這個目錄創建兩個目錄,而是我可以使用一個指令來顯示,然後綁定到模型進行編輯。 – Kalpesh