我试图在此控制器中实现一个带有角度的简单$ http帖子.
app.controller('LoginCtrl',['$scope','admin','$http',function($scope,$http,admin){
$scope.isAdmin = admin.isAdmin;
$scope.logout = admin.logout;
$scope.login = function(){
if(!$scope.username || !$scope.password ){ return; }
$http.post('/login',{ username: $scope.username, password: $scope.password });
$scope.username = '';
$scope.password = '';
};
}]);
Run Code Online (Sandbox Code Playgroud)
这部分
$http.post('/login',{ username: $scope.username, password: $scope.password });
Run Code Online (Sandbox Code Playgroud)
抛出这个错误
TypeError: undefined is not a function
at l.$scope.login (http://localhost:3000/javascripts/angularApp.js:165:9)
at hb.functionCall (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js:198:426)
at Cc.(anonymous function).compile.d.on.f (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js:214:485)
at l.$get.l.$eval (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js:126:193)
at l.$get.l.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js:126:419)
at HTMLFormElement.<anonymous> (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js:215:36)
at HTMLFormElement.c (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js:32:363)
Run Code Online (Sandbox Code Playgroud)
这是ui-view的HTML.
<script type="text/ng-template" id="/login.html">
<button id="logout" class="btn btn-default" ng-click="logout()" ng-show="isAdmin()">Log Out</button>
<div …Run Code Online (Sandbox Code Playgroud) 我知道python需要该__ init __.py文件才能将目录识别为python包,这样我们就可以将子模块导入到我们的程序中.我可以看到类的相似性以及如何使用init来执行必要的代码.
但是,在python文档中,这一行让我困惑,
这样做是为了防止具有通用名称的目录(例如字符串)无意中隐藏稍后在模块搜索路径上发生的有效模块.
如下所示https://docs.python.org/2/tutorial/modules.html#packages
有人可以澄清一下吗?
我一直想知道的事情,javascript(或一般语言)如何使用'alternate'语法来声明内置对象的实例化?例如.
// This being the same as..
var array = new Array('hi','there');
// This.
var array = ['hi','there'];
// or
var myFun = new Function("a","b","return a * b");
// being the same as..
var myFun = function(a,b){ return a * b }
Run Code Online (Sandbox Code Playgroud)
如果我在自己的图书馆工作,有什么方法可以做到这一点吗?说我想为特定的东西制作一些新的语法?原型方法中有什么东西吗?或者这是否超出了开发人员的捕获范围,只有在W3的掌握之内?
John Resig的jQuery似乎有一个独特的语法
$('.class').css({'color':'#000'});
Run Code Online (Sandbox Code Playgroud)
为了获得这种级别的定制,他还需要做些什么吗?或者这是一件事......
// Obviously just a very simple example.
var $ = function(param){
return document.querySelectorAll(param);
}
Run Code Online (Sandbox Code Playgroud)
我很想知道并期待听到您的回答,谢谢.