我有2个以下的文件,index.html文件使用angular到ajax.html进行ajax调用,ajax.html文件包含一些角度代码,我需要在index.html中呈现ajax.html的角度代码所以我可以在div#listelement中替换它。我无法获得渲染代码
的index.html(代码)
<!DOCTYPE html>
<html lang="en" ng-app="myAppUpdate">
<head>
<meta charset="UTF-8">
<title>Angular Ajax HTML Render</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-controller="myControllerUpdate">
<div id="listelement">
<li>old data</li>
<li>old data v2</li>
</div>
<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) {
console.log('inside');
$http.get('ajax.html')
.success(function (data) {
console.log(data);
console.log('working');
var html = jq('#listelement').html(data);
$compile(html)($scope);
// var newstuff = $formBlock.html(response);
// $compile(newstuff)(scope);
});
});
</script>
</body>
</html>
ajax.html(代码)
<div data-ng-controller="myController">
<li ng-repeat="x in data">
{{x}}
</li>
</div>
<script>
var myApp = angular.module('myAppUpdate',[])
myApp.controller('myController',function ($scope) {
$scope.data = ['1','2','3'];
});
</script>
</body>
</html>
答案 0 :(得分:0)
我已经创建了一个plnkr,它现在似乎正在工作
https://plnkr.co/edit/dcEth90yfuN3DtxIHHdI?p=preview
问题与此有关:
import subprocess
import shlex
p = subprocess.Popen(shlex.split("/usr/bin/myprogram --path /home/myuser")
https://docs.angularjs.org/guide/module
请注意使用angular.module(&#39; myModule&#39;,[])将创建 模块myModule并覆盖任何名为myModule的现有模块