I encountered an issue while using Material Angular framework and md-autocomplete. The error message I receive is: Cannot read property 'success' of undefined. Below is the snippet of my code:
/*My app.js*/
var app = angular.module('app', ['ngRoute', 'ngMaterial']); //, 'ui.utils.masks'
app.config(function ($routeProvider) {
$routeProvider
.when('/', { controller: 'DemoCtrl', templateUrl: 'view/paginaTeste.html' })
.otherwise({ templateUrl: '404.html' });
});
app.run(function ($rootScope) {
$rootScope.urlServico = 'http://localhost:58999/';
});
/*My controller*/
(function () {
'use strict';
angular
.module('app')
.controller('DemoCtrl', DemoCtrl)
.config(function ($mdThemingProvider) {
$mdThemingProvider.theme('default')
.primaryPalette('blue');
});;
function DemoCtrl($timeout, $q) {
var self = this;
// list of `state` value/display objects
self.states = loadAll();
self.selectedItem = null;
self.searchText = null;
self.querySearch = querySearch;
// ******************************
// Internal methods
// ******************************
/**
* Search for states... use $timeout to simulate
* remote dataservice call.
*/
function querySearch(query) {
var results = query ? self.states.filter(createFilterFor(query)) : [];
return results;
}
/**
* Build `states` list of key/value pairs
*/
function loadAll() {
var allStates = 'Alabama, Alaska, Arizona, Arkansas, California, Colorado, Connecticut, Delaware,\
Florida, Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky, Louisiana,\
Maine, Maryland, Massachusetts, Michigan, Minnesota, Mississippi, Missouri, Montana,\
Nebraska, Nevada, New Hampshire, New Jersey, New Mexico, New York, North Carolina,\
North Dakota, Ohio, Oklahoma, Oregon, Pennsylvania, Rhode Island, South Carolina,\
South Dakota, Tennessee, Texas, Utah, Vermont, Virginia, Washington, West Virginia,\
Wisconsin, Wyoming';
return allStates.split(/, +/g).map(function (state) {
return {
value: state.toLowerCase(),
display: state
};
});
}
/**
* Create filter function for a query string
*/
function createFilterFor(query) {
var lowercaseQuery = angular.lowercase(query);
return function filterFn(state) {
return (state.value.indexOf(lowercaseQuery) === 0);
};
}
}
})();
<!DOCTYPE html>
<html ng-app="app">
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=RobotoDraft:300,400,500,700,400italic">
<meta name="viewport" content="initial-scale=1" />
</head>
<body>
<div layout="column" ng-view></div>
<!-- Angular Material Dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.js"></script>
<script src="/view/app.js"></script>
<script src="/view/controller/DemoCtrl.js"></script>
</body>
</html>
EDIT This is my page paginaTeste.html:
<md-content>
<form name="frmTeste">
<section>
<md-subheader class="md-primary">Novo Teste</md-subheader>
<md-list layout="column" layout-padding>
<md-item>
<md-item-content>
<p>The following example demonstrates floating labels being used as a normal form element.</p>
<div layout-gt-sm="row">
<md-input-container flex>
<label>Name</label>
<input type="text" />
</md-input-container>
<md-autocomplete flex
ng-disabled="DemoCtrl.isDisabled"
md-no-cache="DemoCtrl.noCache"
md-search-text="DemoCtrl.searchText"
md-items="item in DemoCtrl.querySearch(ctrl.searchText)"
md-item-text="item.display"
md-floating-label="Favorite state">
<span md-highlight-text="DemoCtrl.searchText">{{item.display}}</span>
</md-autocomplete>
</div>
</md-item-content>
</md-item>
</md-list>
</section>
</form>
I am seeking assistance with debugging my code as I am unsure about what's causing the issue. Any help would be greatly appreciated. PS: Please excuse any errors in my English, thank you.
Thank you.