angular service/directive

时间:2021-11-30 08:02:11
<html class=" js cssanimations csstransitions" ng-app="phonecatApp" >
<head>
<title>{{title}}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="/scripts/service/css/font.css" rel="stylesheet" type="text/css">
<link href="/scripts/service/css/style.css" rel="stylesheet" type="text/css" media="all">
<link rel="stylesheet" type="text/css" href="/scripts/service/css/magnific-popup.css"> </head>
<body ng-controller="controller1">
                            <div class="cart">
<a class="popup-with-zoom-anim" href ng-click="callNotify('message');">NOTIFY</a>
</div>
  <!--<div my-Directive></div>
{{title}}-->
<script type="text/javascript" src="/Scripts/angular.min.js"></script>
<script type="text/javascript">
var phonecatApp = angular.module('phonecatApp', []); phonecatApp.controller('controller1', ['$scope', 'notify', function ($scope,notify) {
$scope.title = "Compare";
$scope.click1 = function () { alert('abc'); };
$scope.callNotify = function (msg) {
notify(msg);
};
$scope.phones = [
{
'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.'
},
{
'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.'
},
{
'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.'
}
];
}]); phonecatApp.directive('myDirective', function () {
return {
template: 'Name: {{phones[0].name}}'
};
}); phonecatApp.factory('notify', ['$window', function (win) {
return function (msg) {
console.log('function in service ' + msg);
return false;
};
}]);
</script>