问题
This might not be an angularJS problem but I am at my wit's end here. The code is shown below:
prep.directive('resultgraph', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
//** scope accessible here **
DomReady.ready(function () {
ThreeBox.preload([
'/scripts/lib/snippets.glsl.html',
], function () {
//....scope not accessible here
How do I access the scope inside the callback function of 'preload', where it says scope is not accessible here ?
回答1:
If you need the DOM to be ready you can do this inside the link function (the scope will be accessible):
$timeout(function(){
alert('DOM ready');
//** scope accessible here **
});
来源:https://stackoverflow.com/questions/27920293/how-to-access-scope-in-a-function-inside-link-function-in-angularjs-directive