路由设置对象参数规则:
$routeProvider.when(url,{ template:string, //在ng-view中插入简单的html内容 templateUrl:string, //在ng-view中插入html模版文件 controller:string,function / array, //在当前模版上执行的controller函数 controllerAs:string, //为controller指定别名 redirectTo:string,function, //重定向的地址 resolve:object<key,function> //指定当前controller所依赖的其他模块 });
mainApp.factory('MathService', function() { var factory = {}; factory.multiply = function(a, b) { return a * b; } return factory; });
也可以写成:
mainApp.factory('MathService', function() { var factory = { multiply : function(a, b){ return a*b } }; return factory; });
factory的实例
<div ng-app='myApp' ng-controller='MathCtrl'> <input type="text" ng-model='leftNum'> x <input type="text" ng-model='rightNum'> =<span >{{multRes}}</span> </div>
尝试一下 »
1.一个对别人有依赖的东西,它想要单独测试,就需要在依赖项齐备的情况下进行。如果我们在运行时注入,就可以减少这种依赖
2.参数由定义方决定
3.与import还不完全一样
那个 test() 的监听函数里,当如果是编辑状态时,密码和重复密码为空时,保存按钮也可以点,因为编辑状态时 $scope.edit=false,$scope.incomplete=false, 因为没有判断密码和重复密码为空,所以 $scope.error=false;
所以这个有两种方法,一种是判断密码和重复密码为空时让 $scope.error=true;
第二种就是分开创建用户和编辑用户两种状态,创建用户时,所有都不能为空,编辑用户时,密码不能为空。
if ($scope.edit) { if (!$scope.fName.length || !$scope.lName.length ||!$scope.passw1.length || !$scope.passw2.length) { $scope.incomplete=true; } }else{ if (!$scope.passw1.length || !$scope.passw2.length) { $scope.incomplete=true; } }
感谢您的支持,我会继续努力的!
支付宝扫一扫,即可进行扫码打赏哦
750AngularJS 路由
路由设置对象参数规则:
749AngularJS 依赖注入
也可以写成:
748AngularJS 依赖注入
factory的实例
尝试一下 »
747AngularJS 依赖注入
1.一个对别人有依赖的东西,它想要单独测试,就需要在依赖项齐备的情况下进行。如果我们在运行时注入,就可以减少这种依赖
2.参数由定义方决定
3.与import还不完全一样
746AngularJS Bootstrap
那个 test() 的监听函数里,当如果是编辑状态时,密码和重复密码为空时,保存按钮也可以点,因为编辑状态时 $scope.edit=false,$scope.incomplete=false, 因为没有判断密码和重复密码为空,所以 $scope.error=false;
所以这个有两种方法,一种是判断密码和重复密码为空时让 $scope.error=true;
第二种就是分开创建用户和编辑用户两种状态,创建用户时,所有都不能为空,编辑用户时,密码不能为空。