2015-04-01 27 views
1

我有一個關於Angular中依賴注入的問題。AngualrJS ElasticUI依賴注入

我使用ElasticUI: https://github.com/YousefED/ElasticUI

索引,名稱需要在標籤內進行設置。

<body ng-app="tutorial" eui-index="'INDEX_NAME'"> 

是否有可能設置從 「外」 是INDEX_NAME?

angular.module('tutorial', ['elasticui']). ??? 

我對Angular知之甚少。對不起,如果這是一個愚蠢的問題...

感謝您的幫助!

回答

0

這就像將值傳遞給指令一樣。在你的控制器:

.controller('MyController', function($scope) { 
    $scope.indexName = "asdsd"; 
}) 

在HTML:

<body ng-app="tutorial" ng-controller="MyController" eui-index="indexName"> 
+0

太棒了!非常感謝! – 2015-04-01 12:16:04

1

您需要在「IndexVM」實例更改索引的名字,然後就刷新界面。下面是它的代碼:

.controller('MyController', function($scope) { 
    $scope.IndexName="abc"; 
    $scope.changeIndexName(field); 
    $scope.indexVM.index=$scope.IndexName; 
    $scope.indexVM.refresh(false); 
}); 
+0

爲我節省了大量的時間,我在euiIndex指令級別攻擊了這個,但沒有運氣。接受的答案雖然有意義,但由於缺乏更新而無法爲我工作。謝謝! – omenclature 2016-03-22 19:34:52