I have called the data from server using ngResource
. however, i have figured out that for some reason, my controller is called twice.
Here is my code;
App.js file
// declare a module
var blogApp = angular.module('blogApp', ['ngResource']);
HomeController.js file;
blogApp.controller("HomeController", function ($scope, $resource) {
var HotNews = $resource('/api/article/hotnews?culture=en-US');
$scope.news = HotNews.query();
alert("hello"); //here i see hello alert box two times
});
my view;
<ul id="news" data-ng-controller="HomeController">
<li data-ng-repeat="headline in news">
{{headline.description}}
<a href="#" title="Read More">» more</a>
</li>
</ul>
Updated: the issue is in fancybox.js
file that is in main layout;
<html data-ng-app="blogApp">
the source files are;
<!-- JS -->
<script src="/Content/scripts/lib/angular.min.js"></script>
<script src="/Content/scripts/lib/angular-resource.min.js"></script>
<script src="/Content/scripts/app/app.js"></script>
<script src="/Content/scripts/app/controllers/HomeController.js"></script>
@Scripts.Render("~/bundles/jquery")
<script src="/content/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
when i comment out the fancybox, all works fine but when i add it back, i get two times alert box;