missgg missgg - 1 year ago 102
Smarty Question

Loading message or spinner icon before JSON loads in the same file as angular module and controller

I am trying to figure out a way to not use $http.get() or $resource to load my JSON data from a separate file or URL since I can load my JSON data using a smarty code like $scope.products = {$data}; I want to load a spinner icon or a "loading" msg before my JSON data loads since the curly braces from angular code are ugly to display. Here is my code below and any thoughts would be appreciated.

<script type="text/javascript">
var app= angular.module('mysearch', []);
app.controller('mysearchController', ['$scope', function($scope){
$scope.products = {$data};

<div ng-app="mysearch">
<div ng-controller="mysearchController">
<div ng-repeat="item in products">
<p> {{item.title}}</p>

Answer Source

You should be using ng-cloak directive. It prevents the document from showing unfinished AngularJS code while AngularJS is being loaded. An example of such is :

  <element ng-cloak>{{yourdata}}</element>

Edit 1:


Use ng-hide to show your spinner for the time being your angular loads and ng-show to show when your scope has loaded