내 컨트롤러에 배열이 포함되어 있습니다. 배열의 각 항목은 템플릿이있는 지시문입니다. 새로운 광고문을 만들 때 지시어에 대한 가치를 얻으려면 어떻게해야합니까? 새 항목을 푸는 경우 지시문에 ID를 보내려고합니다.변수를 지시문에 전달 (배열 푸시)
컨트롤러
(function() {
'use strict';
angular
.module('app')
.controller('dashboardController', dashboardController);
dashboardController.$inject = ['$scope', '$timeout', '$state', 'apiService'];
function dashboardController($scope, $timeout, $state, apiService) {
$scope.newCMP = newCMP;
$scope.openCMPArray = [];
function newCMP() {
$scope.openCMPArray.push({id:"3"});
}
}
})();
지침
(function() {
'use strict';
angular
.module('app')
.directive('gpCmpForm', cmpForm);
function cmpForm() {
return {
scope: {
id: '=id' //I've tried doing a lot of different mapping here
},
restrict: 'A',
templateUrl: '/app/views/cmpForm.html',
controller: function ($scope) {
$scope.test = "342";
}
}
};
})();
어떻게 만들 때 지시어는 ID를 얻을 수 있습니까?
HTML의 모양은 어떻습니까? 그것이 바로이 id를 지시어 범위에 바인딩하기 때문입니다. –