Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple angularjs app view not loading

Tags:

angularjs

I'm trying to get into angularJS by writing the most basic app. However I'm unable to get even this small amount of code working - the controller doesn't seem to be displaying any of the views. This is almost a direct copy from a popular angularjs video I saw online. I have a feeling its not something big, and my guess is that I possibly have something wrong with the ng-view.

Any insight on what I'm doing wrong would be helpful.

index.html

<!doctype html>
<html ng-app="fastsql">
<head>
</head>
<body>
<div class="well">
  <div ng-view></div>
</div>


<script src="angular.min.js"></script>
<script src="fastsql.js"></script>  

</body>
</html>

fastsql.js

// setup fastsql as angular app "module"
var fastsql = angular.module("fastsql", []);

// set routeProvider rules in .config()
fastsql.config(function($routeProvider) {

// set what views are displayed for each change in the URL.
$routeProvider
.when("/", { controller: 'loginCntl', templateURL: 'test.html' })
.otherwise({ redirectTo: '/' });

});

// controllers
fastsql.controller("loginCntl", function($scope) { $scope.message = "hey"; });
like image 420
zach Avatar asked Feb 14 '26 06:02

zach


2 Answers

templateURL should have been templateUrl.

like image 199
zach Avatar answered Feb 15 '26 20:02

zach


you need to pass an array into the config function, the name of the services to injected, and then the function in to which they are injected.

fastsql.config(["$routeProvider", function($routeProvider) {
 // do your thing
}]);
like image 24
Jason Avatar answered Feb 15 '26 22:02

Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!