angular.js添加自定义服务依赖项方法
<!DOCTYPE html> <html lang="en" ng-app="myapp"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="../js/angularjs.js"></script> <style type="text/css"> *{ margin:0px; padding:0px; } body{ font-size: 32px; } .show{ background: #eeeeee; padding: 8px; width: 500px; margin:8px 0px; } </style> </head> <body> <div ng-controller="sub"> <div class="show">选择:{{result}}</div> <button ng-click="confrim('要删除吗?')">删除</button> </div> </body> <script> var app=angular.module('myapp', []); app.service('$student',function($window){ return function(msg){ return $window.confirm(msg) ?"确定":"取消"; } }) app.controller('sub',function($scope,$student){ $scope.confrim=function(msg){ $scope.result=$student(msg); } }) </script> </html>