Ich habe eine Angular.js App und aus irgendeinem Grund kann ich nichts aus dem Objekt $scope
in das HTML interpolieren. Mein MainCtrl
Controller und MainFactory
funktionieren gut zusammen, und ich kann ein Diagramm an den HTML-Code richtig anfügen, nur die $scope
interpolieren funktioniert nicht. Hier ist der Code, den ich derzeit haben:
EDIT: ich dies mit der Ansicht Rendering-Engine Swig
var app = angular.module("myapp", []);
app.controller('MainCtrl', function($scope, MainFactory) {
$scope.firstName = 'George';
console.log('scope :', $scope); // logs the $scope obj correctly but doesn't have my firstName property on it
MainFactory.fetchBacktestedDataByAllocationId()
.then(data => {
// draw and append chart - works fine
});
});
app.factory('MainFactory', function($http) {
var MainFactory = {};
MainFactory.fetchBacktestedDataByAllocationId = function() {
return $http.get('/path/to/api')
.then(response => {
return response.data;
})
};
return MainFactory;
});
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script src="/widget/assets/d3.version3.js"></script>
<script src="/widget/assets/backtested-growth/backtested-data-chart.js"></script>
<script src="/widget/assets/backtested-growth/backtested-growth.script.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="MainCtrl">
<div style="width: 100%;">
<div id="graph-div"></div>
<br>
<p>First Name: {{ firstName }}</p>
</div>
</div>
</body>
</html>
Was mache ich falsch?
@anuragasaurus Das war das Problem, danke! – georgej
@georgej Einmal hat es mich auch lange gestört :) – nrgwsth