有没有办法从纯 JavaScript 中使用 $compile ?我正在结合基本的 javascript 和我使用 Angular 的地方并且找不到如何做这样的事情的方法:http: //jsfiddle.net/DavidSlavik/bFdcJ/1/
我想我需要使用 $compile 但从没有任何范围的地方。
angular.module('myApp', []);
function ExpensesCtrl($scope) {
// Here are some master functions...
}
$(function () {
// Here is the Ajax function that returns html from my MVC action processed with Razor
// Here I'm not using AngularJS and scopes...
var htmlFromAjax = '<div id="mapOrder" ng-controller="sortable"><div ng-repeat="item in SortItems">{{item.Title}}</div></div>';
$('body').append(htmlFromAjax);
});
function sortable($scope, $http, $element) {
// Here is the Ajax function that return JSON object. For example it is commented and used static variable SortItems in scope.
//$http.get('someUrlWitchReturnsJsonObject')
// .success(function (e) {
// $scope.SortItems = e;
// });
$scope.SortItems = JSON.parse('[{"Title":"ddddddd","MapId":5,"Order":0},{"Title":"Moje mapa","MapId":3,"Order":2},{"Title":"asdas","MapId":4,"Order":3},{"Title":"asds","MapId":7,"Order":4},{"Title":"Pokus","MapId":8,"Order":5},{"Title":"Hello world!!!","MapId":1,"Order":10}]');