javascript - Read a file from JQuery inside AngularJS -


hi i'm beginner @ programming. i'm trying put data json file variable

i want have angularjs put text html document this

{{ data.text }} 

and text based off of json file have in app.js, set data using jquery:

myapp.controller('ctrl', function ($scope, $http) {  $.getjson("../static/file.json", function(data) {    $scope.data = data;  }); 

but nothing shows initially. when log $scope.data, turns out undefined. know json file correct because if put code in method called

$scope.foo = function(){$.getjson("../static/file.json", function(data) {        $scope.data = data;      });} 

and have button activate this, it'll work fine. want there initially.

try

$.getjson("/static/file.json", function(data) {    $scope.data = data; }); 

then load file web http://xxx/static/file.json, not file system.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -