I need some assistance with this issue. When I use $scope.nameStaff
in ng-repeat
, the value appears as undefined
. I'm puzzled by why it's returning undefined
.
Here is the code snippet:
<div ng-controller="MyCtrl">
<div ng-repeat="form in form">
<input type="text" ng-model="nameStaff" />
<input type="text" ng-model="idStaff" />
<button ng-click=addDetail()>add
</button>1
</div>
{{form}}
</div>
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.form = [{
companyName: "company1",
companyAddress: "company address",
staff: [{
name: "men",
id: "123"
}]
}, {
companyName: "company1",
companyAddress: "company address",
staff: [{
name: "men",
id: "123"
}]
}]
$scope.addDetail = function() {
alert($scope.nameStaff);
$scope.form[0].staff.push({
name: $scope.nameStaff,
id: $scope.idStaff
});
}
}