2016-04-27 53 views
0

我創建一個變量拒絕一個又一個,在「First.js」文件:角呼叫從不同的.js變量文件

var nosubs = _.reject(subs, function (bi) { return bi.ParentBoardbookItemId === '0'; }); 

是否有可能把這個變量(nosubs)以「二。 js「文件? 我該怎麼做?

請注意,我a

預先感謝您!

+0

你能告訴我到底你要通過引用變量來達到什麼目的嗎?這將幫助我給出更好的答案 –

+0

以上是帶下劃線的Javascript。你想只使用另一個文件中的變量nosubs,或者你想使用角? –

回答

1

有很多方法可以做到這一點。最好的角度是不使用變量。但要將您的數據存儲在服務中。

// simplified version of defining the service 
app.service("myService", function(){ 
    this.setData = function(data){ 
     this.data = data; 
    }; 
    this.getData = function(){ 
     return this.data; 
    }; 
    return this; 
}); 
// now you just have to inject it in your controllers/run blocks and you can use myService.data. 

另一種解決方案是將它存儲在$ rootScope中。

如果你想/需要別的東西,我們需要更多的信息。

0

您可以將varible存儲在rootcope中以便在其他文件中訪問。

$rootScope.nosubs = _.reject(subs, function (bi) { return bi.ParentBoardbookItemId === '0'; });