我有一個指令<stu-directive>
,其中包含輸入字段和一個select
。如何獲取在指令函數中鍵入或選擇的值。如何獲取指令內輸入字段的值
<div class="certFull">
<stu-directive obj ="certObj" ng-model="stuDirModel"></stu-directive>
<div class="addDir col-md-12 mg">
這是該指令的HTML:
<div ng-transclude class="container-fluid stuDirectiveClass mg">
<div class="rows">
<div class="col-md-12 mg">
<div class="form-group">
<div class="rows">
<div class="col-md-6"><label for="studentNameId">Student name</label></div>
<div class="col-md-6">
<select class="form-control" ng-model="selectStudent"> <!--get this value-->
<option>Stu1</option>
<option>Stu2</option>
<option>Stu3</option>
<option>Stu4</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group mg">
<div class="rows">
<div class="col-md-6"><label for="studentNameId">Student mark</label></div>
<div class="col-md-6">
<input type="text" class="form-control" ng-model="studentMark" placeholder="Student mark" /> <!--get this value-->
</div>
</div>
</div>
</div>
</div>
該指令功能:
uiRouteApp.directive('stuDirective', function() {
return {
restrict: 'E',
//scope: {
// externalObj: '=obj'
//},
transclude: true,
templateUrl: 'htmlFiles/stuDirective.html',
link: function link(scope, element, attrs) {
//how do i access the input field values in directive
},
controller: ['$scope','$timeout', function ($scope,$timeout) {
console.log($scope.selectStudent); // undefined
}]
}
})
認沽值選項 –
@BurakAkyıldız。如何訪問它後? – Abhi