親コントローラーのコンポーネントからのデータの受理角。コンポーネントから親コントローラーへのデータの受け渡し
index.htmlを
<div ng-controller="formController">
<phones-list phone="phone"></phones-list>
<button ng-click="saveForm()">Save</button>
</div>
form.controller.js
var app = angular.module('myApp');
app.controller('formController', ['$scope', function($scope) {
$scope.saveForm = function() {
console.log($scope.phone)
}
}]);
phoneList.component.js
var app = angular.module('myApp');
app.component('phonesList', {
templateUrl: '/scripts/components/phones/phonesList.template.html',
controller: 'phonesListController',
bindings: {
phone: '='
}
});
phoneList.template.html
: 私はこのコードを持っています<select name="" id="" ng-change="$ctrl.change()" ng-model="$ctrl.phone">
<option ng-repeat="phone in $ctrl.phones">{{ phone.name }}</option>
</select>
phoneList.controller.js
var app = angular.module('myApp');
app.controller('phonesListController', function() {
this.phones = [
{
name: 'ABC',
number: '723-543-122'
},
{
name: 'ABCDE',
number: '324-531-423'
}
];
this.change = function() {
console.log(this.phone)
}
});
だから私は、携帯電話との選択リストを持っています。私が望むのは、フォームを選択して送信した後にformControllerで電話オブジェクトを取得することです。今のところ私はテキストの価値しか得ていません。
$ scope.phoneSelected(IN電話)は、依然として 'ABC' オブジェクトない{名: 'ABC'、数: '723-543-122'}のようなテキストされます – corneliusz