Is there a way to initialize an Angular model using a JSON object that is embedded within an HTML page? Take this as an example:
<html>
<body>
<script type="text/javascript" charset="utf-8">
var tags = [{"name": "some json"}];
</script>
<ul>
<li ng-repeat="tag in tags">{{tag.name}}</li>
</ul>
</body>
</html>
The tags
field doesn't resolve because it's being looked up in the $scope
. I attempted to access the tags
field in my controller like so:
function TagList($scope, $rootScope) {
$scope.tags = $rootScope.tags;
}
However, this method isn't successful.
It only works if I directly include the TagList
within the HTML page and render the JSON directly into this function.
Is there a way to access the tags
field in a separate JavaScript file within an Angular controller?