我在 Controller 中获得了值。我希望这些值能够在指令内部访问。有可能吗?
$scope.gridheader = [
{ headerName: "ID", field: "ID", seqNo: 0,checkboxSelection: true },
{ headerName: "Patient Name", field: "PatientName", seqNo: 1 },
{ headerName: "Gender", field: "Gender", seqNo: 3 },
{ headerName: "Age", field: "Age", seqNo: 2 },
{ headerName: "Phone Number", field: "mobileNumber", seqNo: 4 }
];
$scope.rowData = [
{ ID: "09-14-002880", PatientName: "PRAVEEN KUMAR", Gender: "Male", Age: "20", mobileNumber: 9879878971, patientId: "test" },
{ ID: "09-13-000188", PatientName: "VAR", Gender: "Male", Age: "20", mobileNumber: '', patientId: "ZXC12" },
{ ID: "09-05-019825", PatientName: "KARMA", Gender: "Male", Age: "29", mobileNumber: '', patientId: "ZA2545635" },
{ ID: "09-04-010524", PatientName: "FRANKLIN ANTHONY", Gender: "Male", Age: "20", mobileNumber: '', patientId: "Z7552396" },
{ ID: "09-08-009303", PatientName: "DARYOUSH", Gender: "Male", Age: "29", mobileNumber: '', patientId: "Z2548467" },
{ ID: "09-12-031048", PatientName: "SMITA", Gender: "Female", Age: "20", mobileNumber: 9880222187, patientId: "Z2296538" },
{ ID: "09-11-026001", PatientName: "ADITYA DILIP", Gender: "Male", Age: "29", mobileNumber: '', patientId: "Z2277913" }
];
$scope.filterData = $scope.rowData;
$scope.searchName = function() {
$scope.searchData = $scope.quickregistration.SearchPatientId;
if($scope.filterData != undefined ){
$scope.rowData = $filter('filter')($scope.filterData, $scope.searchData);
for(var key in $scope.rowData) {
$scope.value = $scope.rowData[key];
} // here i got the values.. this value should be get access inside the directive
最佳答案
这应该很容易研究。您是否在其他地方寻找答案?
这是指令和使用指令的 html 之间的数据绑定(bind)的简短示例。
使用= 进行数据绑定(bind),使用@ 进行文本绑定(bind),指令中的CamelCase 替换为html 样式的连字符(attributeName -> attribute-name)
如果你确切地知道你正在使用这个指令的 Controller ,你可以使用 $parent 访问父范围(例如 $parent.someFunction())。
在 HTML 中
<my-input-field model="modelValue" attribute-name="{{attributeName}}"></my-input-field>
在指令中:
scope: {
model: '=model'
attributeName: '@attributeName'
}
阅读:http://onehungrymind.com/angularjs-sticky-notes-pt-2-isolated-scope/
关于javascript - 如何从 Controller 访问值到angularJs中的指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35698611/