Ich habe unter 2 Dateien, index.html Dateien macht einen Ajax-Aufruf mit eckigen zu ajax.html, ajax.html Datei enthält einige Winkelcode, ich brauche den gerenderten Winkel-Code von Ajax .html in index.html, also könnte ich es in div # Listenelement ersetzen. Ich bin nicht in der Lage, um den CodeWie bekomme ich Render-Daten von angular Ajax Call
index.html (Code)
<!DOCTYPE html>
<html lang="en" ng-app="myAppUpdate">
<head>
\t <meta charset="UTF-8">
\t <title>Angular Ajax HTML Render</title>
\t <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
\t <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-controller="myControllerUpdate">
<div id="listelement">
\t <li>old data</li>
<li>old data v2</li>
</div> \t
<script>
var jq = $.noConflict();
var myAppUpdate = angular.module('myAppUpdate',[]);
console.log('outside');
// var myApp = angular.module('myApp',['ui.bootstrap']);
myAppUpdate.controller('myControllerUpdate', function ($scope,$http,$compile) {
\t console.log('inside');
$http.get('ajax.html')
\t .success(function (data) {
console.log(data);
console.log('working');
var html = jq('#listelement').html(data);
\t \t \t \t $compile(html)($scope);
// var newstuff = $formBlock.html(response);
\t // $compile(newstuff)(scope);
});
});
</script>
</body>
</html>
ajax.html (Code)
<div data-ng-controller="myController">
\t <li ng-repeat="x in data">
\t \t {{x}}
\t </li>
</div>
\t
<script>
var myApp = angular.module('myAppUpdate',[])
myApp.controller('myController',function ($scope) {
\t $scope.data = ['1','2','3'];
});
</script>
</body>
</html>
Sie sollten Routing für bessere Präferenz verwenden. – Jigar7521