指令中的控制器未被读取

时间:2018-01-08 22:22:49

标签: angularjs

它会打印2,但不会打印3"use strict"; console.log('1'); module.exports = TestDirective; TestDirective.$inject = []; function TestDirective() { console.log('2'); return { restrict: "E", scope: { user: "=", onComplete: "&", hideSubmitButton: "=?" }, templateUrl: "/test.html", controller: TestCtrl4, controllerAs: "testCtrl4", bindToController: true }; } TestCtrl4.$inject = ["$log", "$scope"]; function TestCtrl4($log, $scope) { var vm = this; console.log('3'); } 。这有什么不对?

java.lang.NullPointerException: Location is required.

1 个答案:

答案 0 :(得分:0)

编辑: 经过进一步阅读,我发现"use strict"不应该影响console.log()语句的行为。您只需致电TestDirective();

可能是这样,因为你处于严格模式,函数体中的代码在被调用之前不会被评估。

来自:https://docs.microsoft.com/en-us/scripting/javascript/advanced/strict-mode-javascript

"use strict";  
function testFunction(){  
    var testvar = 4;  
    return testvar;  
}  

// This causes a syntax error.  
testvar = 5;  

我会通过删除"use strict"或调用您的函数来测试,例如:

const testVar = TestDirective();