I am trying to understand how UI-Router works with Angular and I am having a tough time.
I have an index:
<body>
<div ui-view></div>
<!--Location of file holding app-->
<script src="App/indexApp.js"></script>
<!--source of state2 Controller-->
<script src="App/itemsController.js"></script>
</body>
an app.js:
var app = angular.module("ITS", ['ui.router'])
.config(['$httpProvider', '$stateProvider', '$urlRouterProvider', function ($httpProvider, $stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/home");
$stateProvider.state('home', {
url: "/home",
templateUrl: "Home.html",
controller: 'IndexCtrl'
})
$stateProvider.state('newItem', {
url: "/newItem",
templateUrl: "new.html",
controller: 'ItemCtrl'
})
a file for the controller:
app.controller("ItemCtrl", ['$scope', '$location', '$state',
function ($scope, $location, $state) {
$scope.testButton = function () { //Test FUNC
$window.alert("hey");
}
$scope.title="hello";
and finally an html page for the view:
<div ng-app="ITS" ng-controller="ItemCtrl">
<body>
<button ng-click="testButton()">Test</button>
<input type="text" ng-model="title"/>
</body>
</div>
PROBLEM: Home loads fine, and I can navigate from "Home" to "New" with a ui-sref, and I can see the test button. I know the controller is working and is being accessed, but when I click the button nothing pops up, and the field associated with "title" is not populated by $scope.
I have heard resolves are important for loading data before a state is changed, but I cannot seem to find much information on them for a problem like this one. Any help would be most appreciated.