作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用另一个文件的内容填充 anglarjs 函数的内容。可能是js文件,json,txt,我不介意。
test.js
$scope.startTest = function () {
/**
* insert content of details-1.js
*/
}
detials-1.js
var fac = 3;
return fac;
最终的函数看起来像这样
$scope.stratTest = function() {
var fac = 3;
return fac;
}
我的目标是根据您选择的测试拥有不同的测试过程,并从 startTest 函数启动特定的测试过程。
最佳答案
你可能应该做这样的事情。
details-1.js
$scope.tests.myTest = function() {
// Insert test here
}
test.js
$scope.startTest = function() {
// Loop through all tests
for (var key in $scope.tests) {
if ($scope.tests.hasOwnProperty(key)) {
// Execute test
$scope.tests[key]( /* args here */ );
}
}
// Or you could just execute a specific test
$scope.tests.myTest( /* args here */ )
}
注意: $scope.tests
应该在某处初始化。
关于javascript - 如何将文件的内容添加到javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23957276/
我是一名优秀的程序员,十分优秀!