如何设置的范围属性时,则可以通过角度的控制? [英] How to set a property of scope in the controller when it is available in angular?
问题描述
我有一个全球性的JS对象称为实例_
I have a global JS object called instance_
它有一个叫做当前属性_
It has a property called current_
后来得到一个属性调用数据集_
Which later gets a property called dataset_
所以basicaly instance_.current_.dataset _
so basicaly instance_.current_.dataset_
我用这个dataset_属性在div来显示当前的数据集。但是,当控制器由角CURRENT_ initiliased为空。所以我不能使用CURRENT_的dataset_财产我不能设置 $ =范围_ instance_.current_.dataset
为当前_
是空
I use this dataset_ property in a div to show current dataset. But when the controller is initiliased by angular current_ is null. So I cant use dataset_ property of current_ as I cant set $scope = instance_.current_.dataset_
ascurrent_
isnull
我该如何解决这个问题?
How do I solve this?
在解决方案的替代尝试,我怎么能延缓这种特殊的控制器的初始化,直到current_view_仍然空?
an alternative attempt at a solution, how can I delay this particular controller's initialization until current_view_ remains null?
推荐答案
这可能是一个解决方案。工厂添加到您的应用程序,如:
This may be one solution. Add a factory to your app, like this:
myApp = angular.module('myApp', []);
myApp.factory('myGlobalDataSet', function(){
return instance_.current_.dataset_;
});
然后,工厂的值传递到控制器:
Then pass the factory's value into your controller:
function myController($scope, myGlobalDataSet) {
$scope.myGlobalDataSet = myGlobalDataSet;
}
然后在视图里,你应该能够访问myGlobalDataSet变量。如果你用NG-模型比分扳成那么它应该与视图的详细信息,请全球价值进行绑定。
Then within your views you should be able to access the myGlobalDataSet variable. If you tie it with an ng-model then it should bind your global value with the details of the view.
这篇关于如何设置的范围属性时,则可以通过角度的控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!