我想从我本地计算机上的JSON文件中获取数据.但我无法获得数据.它显示$ http的一些跨域错误.
这是我的代码.
angular.module('myApp',[])
.controller('myCtrl', function ($scope, webtest) {
webtest.fetch().then(function (data) {
$scope.accounttype = data;
})
});
.factory('webtest', function($q, $timeout, $http) {
var Webtest = {
fetch: function(callback) {
return $timeout(function() {
return $http.get('webtest.json')
.then(function(response) {
return response.data;
});
}, 30);
}
};
return Webtest;
});
Run Code Online (Sandbox Code Playgroud)
有人请帮我如何显示本地JSON文件中的数据?提前致谢.
我已经用javascript 编写hide()和show()函数,并onmousedown在HTML代码中调用它们.
功能如下:
function show() {
document.getElementById("formDiv").style.display = "block";
}
function hide() {
document.getElementById("formDiv").style.display = "none";
}
Run Code Online (Sandbox Code Playgroud)
我想将其转换为Angularjs代码.我可以这样写吗?
$scope.show = function() {
document.getElementById("formDiv").style.display = "block";
}
$scope.hide = function() {
document.getElementById("formDiv").style.display = "none";
}
Run Code Online (Sandbox Code Playgroud)
我们可以使用document.getElementById()的Angularjs?我是新来的angularjs.有人可以帮帮我吗?