我有一个自定义指令,它具有存储在对象中的值我希望自定义指令输入和下拉的这些值作为对象传递到我指向此指令的页面。这个指令值将被传递到主页面,当我点击应用按钮,这是我的主页上,我试过以下,但无法从我的页面中的自定义指令中使用此指令的值。请建议我如何将指令中的值传递给不同的页面。我需要从请求变量查询对象我在最后将自定义角度指令的值传递到其他页面
自定义指令模板文件指标,仪表板configuration.html
<div>
<span>Service Level (SL)</span>
<select ng-model="selection.serviceLevelOption" ng-options="serviceLevelObject.value as serviceLevelObject.text for serviceLevelObject in selection.serviceLevels.values" ng-init="selection.serviceLevelOption='30'"></select>
<br>
<input type="text" ng-model="selection.inputText" />
</div>
定义在我的主页控制器的功能已经声明了值
自定义指令申报和控制器
function metricsDashboardConfiguration() {
return {
restrict: 'E',
scope: {
query: '='
},
templateUrl: 'metrics-dashboard-configuration.html',
controller: metricsDashboardConfigurationCtrl
};
}
function metricsDashboardConfigurationCtrl($scope) {
$scope.query = {};
$scope.selection = {
serviceLevels: {
values: [
{value : "15" , text : "15"},
{value : "30" , text : "30"},
{value : "45" , text : "45"},
{value : "60" , text : "60"},
{value : "120" , text : "120"}
]
},
inputText: "test"
};
$scope.updateRequest = function() {
$scope.query.inputText = $scope.selection.inputText;
$scope.query.serviceLevels= $scope.selection.serviceLevels;
};
$scope.$watch('selection.inputText', $scope.updateRequest, true);
$scope.$watch('selection.serviceLevels', $scope.updateRequest, true);
的HTML页面,在这里我使用的指令
<metrics-dashboard-configuration query="queryData" update-Queues-Dashboard="updateQueuesDashboard()"></metrics-dashboard-configuration>
您已在metrics-dashboard-configuration.html
文件中使用,我需要自定义指令
$scope.queryData = {
inputText : "",
trailingWindows: []
};
$scope.updateQueuesDashboard = function() {
var request = angular.copy($scope.queryData);
};
更正,这是一个错别字 – zubairm
检查你的观察者$范围。$ watch('selection.inputText',$ scope.updateRequest,true); $ scope。$ watch('selection.trailingWindows',$ scope.updateRequest,true);' –
谢谢现在完成 – zubairm