标签:UNC txt The style ror $.ajax min OLE ext
angularjs中的异步操作,
"异步问题"
1.叫回来 $scope.$apply() angularjs中涉及到数据检查的东西,这个方法表示告诉angularjs,值已经改变了。
2.用angularjs自己的方法 $http.get()
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>angularjs中的异步操作,"异步问题" 1.叫回来 $scope.$apply() 2.用angularjs自己家的 $http.get() </title> <script src="https://cdn.staticfile.org/angular.js/1.5.5/angular.min.js"></script> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> </head> <body ng-app="myApp"> <div ng-controller="main"> <ul> <li ng-repeat="a in arr"> {{a}} </li> </ul> </div> <script type="text/javascript"> let mod = angular.module("myApp", []); mod.controller("main", ["$scope","$http", function ($scope,$http) { $http.get("arr.txt").then(function (res) { console.log(res.data); $scope.arr = res.data; }, function(err){ console.log("失败"); }); //$http.get("arr.txt").then((res) => { // $scope.arr = res.data; //}, (err) => { // alert("失败"); //}); //setTimeout(function () { // $scope.arr = [12, 5, 8]; // $scope.$apply(); //}, 10); //$.ajax({ // url: "arr.txt", // dataType: "json", // success(res) { // alert(res); // $scope.arr = res; // $scope.$apply(); // }, // error() { // alert("错了"); // } //}); // $scope.arr = [12,5,8]; }]); </script> </body> </html>
标签:UNC txt The style ror $.ajax min OLE ext
原文地址:https://www.cnblogs.com/zhumeiming/p/9813449.html