I am trying to use a controller that I wrote and saved in a controller.js file, but it won't work in my html code. I have the code written as: (This is the version that doesn't work correctly)
<div ng-app="myApp" ng-controller="movieCtrl">
..bit of my html code..
</div>
<script src="controller.js"></script>
This version however works just fine:
<div ng-app"myApp" ng-controller="movieCtrl">
irrelavent html code here
</div>
<script>
var app = angular.module('myApp', []);
app.controller('movieCtrl', function($scope, $http) {
$scope.$watch('search', function() {
fetch();
});
$scope.search = "tt2975590";
function fetch() {
$http.get("http:www.omdbapi.com/?i=" + $scope.search + "&plot=full&r=json")
.then(function(response) {
$scope.details = response.data;
});
}
$scope.update = function(movie) {
$scope.search = movie.Title;
}
});
</script>
How do I get it to work with the controller in its own controller.js file?