単純な例を明確にしてください: この例では、angularApp.jsで計算されたmachineLengthを使用するにはどうすればよいですか? 今のところ、angleApp.jsで計算されたものではなく、空のオブジェクトを出力します。他のjsファイルで計算された変数にアクセスする方法は?
<html>
<head>
<script src="...">...</script>
<script>
let machineLength={};
</script>
<script src="angularApp.js"></script>
</head>
<body>
...
<script>
console.log(machineLength);
// here is a lot of code use machineLength to render scene of models with three.js
//the machineLength is the render region width, height. length
</script>
</body>
</html>
angularApp.js:
let sliceApp = angular.module('sliceConfig', []);
sliceApp.
.controller('sliceConfigController', ['$scope', '$http', function($scope, $http)
{
$http.get("http://xxxxx/getSliceConfig")
.success(function(response)
{
$scope.config = [];
$scope.config.machine_width = machineLength.x = parseFloat(response.config.machine_width);
...
}
}]);
どれが助けが理解されるであろう!応答が到着する前に、問題がangularApp.js
あるProviders value recipe
var myApp = angular.module('myApp', []);
myApp.value('m_width', '100'); //some init value
myApp.controller('DemoController', ['m_width', function DemoController(m_width) {
$http.get("http://xxxxx/getSliceConfig")
.success(function(response)
{
$scope.config = [];
var x = //something from response;
$scope.$emit('eventName', { width: x });
...
}
}]);
myApp.controller('otherController', ['m_width', function otherController(m_width) {
$scope.$on('eventName', function (event, args) {
$scope.message = args.width;
console.log($scope.message);
});
$scope.width = m_width;
}]);
angular.valueは、あなたがより多くの情報が得られますA.J @ –
を助けるかもしれない、angular.valueをどのように使用する:
代わりに、私は、値プロバイダーを使用することをお勧めしますか?ありがとう –
私は1時間後の例を投稿するつもりで、ノートパソコンにアクセスできない。ありがとうございます(現時点でモバイル通信を使用しています);) –