Here my code:
index.html:
<head>
<script src="angular.js"></script>
<script src="angular-route.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-view></div>
</body>
</html>
script.js:
var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: 'route.html',
controller: 'RouteController',
}).otherwise('/');
}]);
app.controller('RouteController', ['$scope', function($scope) {
$scope.hello='world';
}]);
app.controller('IncController', ['$scope', function($scope) {
$scope.field = '';
$scope.test = function() {
console.log('test=' + $scope.field);
}
}]);
route.html:
<div>
hello world
<div>{{hello}}</div>
<ng-include src="'including.html'"
ng-controller="IncController"></ng-include>
</div>
including.html:
<input type='text' ng-model='field'/>
<input type='button' ng-click='test()'/>
When I click button test() function is calling, but field is always empty. If I make route for including.html it works when I go to this route.