Async problems
Ajax asynchronously requests the data after the data is assigned to $scope when you need to check the $scope data update is not. Otherwise, the data cannot be bound.
<!DOCTYPE HTML><HTMLNg-app= "Test_ajax"> <Head> <MetaCharSet= "Utf-8"> <title></title> <Scriptsrc= "Angular.js"CharSet= "Utf-8"></Script> <Scriptsrc= "Jquery.js"></Script> <Script>Let mod=Angular.module ('Test_ajax', []); Mod.controller ('Main', function($scope) {$.ajax ({URL:'Arr.txt', DataType:'JSON', Success (res) {$scope. arr=Res; $scope. $apply (); //Check}, error () {Alert ('wrong.'); } }); }); </Script> </Head> <BodyNg-controller= "Main"> <ul> <Ling-repeat= "A in arr">{{A}}</Li> </ul> </Body></HTML>
$scope. $apply (); Check
Request data directly with the Angularjs method get method
<!DOCTYPE HTML><HTMLNg-app= "Test_ajax"> <Head> <MetaCharSet= "Utf-8"> <title></title> <Scriptsrc= "Angular.js"CharSet= "Utf-8"></Script> <Script>Let mod=Angular.module ('Test_ajax', []); Mod.controller ('Main', function($scope, $http) {$http. Get ('Arr.txt'). Then (RES)={$scope. arr=Res.data; }, (Err)={alert ('wrong.'); }); }); </Script> </Head> <BodyNg-controller= "Main"> <ul> <Ling-repeat= "A in arr">{{A}}</Li> </ul> </Body></HTML>
Angularjs Data interaction