Google autocomplete suggestion give you popular searches for your typed word. Here I search about different programming languages and frameworks. See what Google suggested me.
Some suggestion are really nice but some are.... see.
Dashboard
$scope.redirectToDraftPage= function () {
$location.path('/draft');
};
(function(){
'use strict';
function ngRedirectTo($window) {
return {
restrict: 'A',
link: function(scope, element, attributes) {
element.bind('click', function (event) {
//assign ng-Redirect-To attribute value to location
$window.location.href = attributes.ngRedirectTo;
});
}
};
}
angular.module('app').directive('ngRedirectTo', ngRedirectTo);
//inject $window service for redirection
redirectTo.$inject = ['$window'];
}());
Dashboard
![]() |
| Routing -Views |
<html ng-app="myDemoApp">
<head>
</head>
<body>
</body>
</html>
//here we need to inject ui.router as we using it for routing
var myDemoApp = angular.module('myDemoApp', ['ui.router']);
//$stateprovider is the service procided by ui.router
myDemoApp.config(['$stateProvider', function ($stateProvider) {
//create route object
var home= {
url: '/home',
templateUrl: 'views/Home.html',
controller: 'HomeCtrl'
},
aboutUs= {
url: '/aboutus',
templateUrl: 'views/AboutUs.html',
controller: 'AboutUsCtrl'
},
contactUs= {
url: '/contactus',
templateUrl: 'views/ContactUs.html',
controller: 'ContactUsCtrl'
};
//Now add these route state privider
$stateProvider
.state('home', home)
.state('aboutus', aboutUs)
.state('contactUs', contactUs);
}]);
myDemoApp.controller('HomeCtrl', function ($scope) {
$scope.message = 'Hello! we are on Home Page';
})
.controller('AboutUsCtrl', function ($scope) {
$scope.message = 'Hello! we are on About Us Page';
})
.controller('ContactUsCtrl', function ($scope) {
$scope.message = 'Hello! we are on Contact Us Page';
});
{{message}}
angular.module('demoMasterPage', ['ui.router'])
.config(['$stateProvider', function ($stateProvider) {
var NavLink1 = {
//Name must be in format Parent.Child
name: 'NavLink1',
url: '/Navlink1',
templateUrl: 'views/Navlink1.html',
controller: 'homeCtrl'
},
NavLink2 = {
name: 'NavLink2',
url: '/Navlink2',
templateUrl: 'views/Navlink2.html',
controller: 'homeCtrl'
},
NavLink3 = {
name: 'NavLink3',
url: '/Navlink3',
templateUrl: 'views/Navlink3.html',
controller: 'homeCtrl'
},
NavLink1One = {
name: 'NavLink1.One',
url: '/Navlink1/One',
templateUrl: 'views/Navlink1/One.html',
controller: 'homeCtrl'
},
NavLink1Two = {
name: 'NavLink1.Two',
url: '/Navlink1/Two',
templateUrl: 'views/Navlink1/Two.html',
controller: 'homeCtrl'
},
// similarly for NavLink1Three,NavLink1Four, NavLink2One, NavLink2Two and so on.
NavLink1OneLink1 = {
name: 'NavLink1.One.Link1',
url: '/Navlink1/One/Link1',
templateUrl: 'views/Navlink1/One/Link1.html',
controller: 'homeCtrl'
},
NavLink1OneLink2 = {
name: 'NavLink1.One.Link2',
url: '/Navlink1/One/Link2',
templateUrl: 'views/Navlink1/One/Link2.html',
controller: 'homeCtrl'
};
//Similarly define all the combination you want to separate
//add routes to stateProvider
$stateProvider.state('NavLink1', NavLink1)
.state('NavLink2', NavLink2)
.state('NavLink3', NavLink3)
.state('NavLink1.One', NavLink1One)
.state('NavLink1.Two', NavLink1Two)
.state('NavLink1.One.Link1', NavLink1OneLink1)
.state('NavLink1.One.Link2', NavLink1OneLink2);
}])
.config(function ($urlRouterProvider) {
//set default page to redirect; if wrong route is given redirect here
$urlRouterProvider.otherwise('/NavLink1/One/Link1');
});
<html ng-app="myDemoApp">
<head>
</head>
<body>
</body>
</html>
<html ng-app="moduleName" >
var moduleName = angular.module('moduleName', [ ] );
// Define sub modules with no dependencies
angular.module('AccountApp', []);
angular.module('LoginApp', []);
// define main module and inject all other modules as dependencies
angular.module('MainApp', [
'AccountApp',
'LoginApp']);
//we passed ngRoute is an external module for handling routing
var moduleName = angular.module('moduleName', ['ngRoute']);
moduleName.config(function ($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
});
});
// create the controller and inject Angular's $scope
moduleName.controller('mainController', function ($scope) {
// create a message to display in our view
$scope.message = 'Hello friend I am Main Controller';
});
and the view for home page will look like:<!-- home.html -->
<div class="content">
<h1>First Application</h1>
<p>{{ message }}</p>
</div>
moduleName.factory('MyService', function () {
var factory = {};
factory.getUser = function () {
//..
}
return factory;
});
<html>
<head></head>
<body>
<script src="angular.js"></script>
</body>
</html>
<html ng-app="">
<head>
<title>Anular JS</title>
</head>
<body>
<div id="container" ng-init="name='Zaheer Ahmed'">
Your Name: <input ng-model="name" type="text" />
Hello AngularJS world!!!!
My Name is {{name}}.</div>
</body>
</html>
<html ng-app="">
<head>
<title>Anular JS</title>
</head>
<body>
<div id="container" ng-init="name='Zaheer Ahmed'">
Your Name: <input ng-model="name" type="text" />
Hello AngularJS world!!!!
My Name is {{name | uppercase}}.
</div>
</body>
</html><html ng-app>
<head>
<title>Anular JS</title>
</head>
<body>
<div id='container' ng-init="names=['Ahmed','John','Jeff',Zaheer']">
search : <input type="text" ng-model="searchKeyword" />
<div style='background:#E4E8EA;padding:10px;'>
Here is list of user name:
<ul ng-repeat="name in names | filter:searchKeyword">
<li>{{name | uppercase}}</li>
</ul>
</div>
</div>
</body>
</html><div ng-controller="MyFirstController">
<h2>List of User</h2>
<ul>
<li ng-repeat="user in Users">
{{user.firstName}} {{user.lastName}} live in {{user.city}}
</li>
</ul>
</div>
Here we are using some AngularJS directives we will see these directives in later articles. Just to make it understand we are telling view that you expect data from this controller using ng-controller directive. It is not necessary to declare a controller here we can set it at run-time with routing.var myApp = angular.module('myApp',[]);
function MyFirstController($scope) {
$scope.Users = [
{firstName: 'Nico',lastName:'braga', city:'Karachi' },
{firstName: 'Bob',lastName:'Rita', city:'Lahore' },
{firstName: 'John',lastName:'Smith', city:'New York' },
];
}
Here is demo fiddle, you can change and practice over it.Please turn off the ad blocker. This is only way that we can earn some penny. Please support us by trun off the ad blocker.
Thank you!!