小编Whi*_*cat的帖子

AngularJS.如何从控制器组件外部调用控制器功能

如何从网页的任何地方(控制器组件之外)调用控制器下定义的功能?

当我按下"get"按钮时它完美地工作.但我需要从div控制器外部调用它.逻辑是:默认情况下我的div是隐藏的.在导航菜单的某处我按下一个按钮,它应该显示()我的div并执行"get"功能.我怎么能做到这一点?

我的网页是:

<div ng-controller="MyController">
  <input type="text" ng-model="data.firstname" required>
  <input type='text' ng-model="data.lastname" required>

  <form ng-submit="update()"><input type="submit" value="update"></form>
  <form ng-submit="get()"><input type="submit" value="get"></form>
</div>
Run Code Online (Sandbox Code Playgroud)

我的js:

   function MyController($scope) {
      // default data and structure
      $scope.data = {
        "firstname" : "Nicolas",
        "lastname" : "Cage"
      };

      $scope.get = function() {
        $.ajax({
           url: "/php/get_data.php?",
           type: "POST",
           timeout: 10000, // 10 seconds for getting result, otherwise error.
           error:function() { alert("Temporary error. Please try again...");},
           complete: function(){ $.unblockUI();},
           beforeSend: function(){ $.blockUI()},
           success: function(data){
            json_answer = eval('(' + data …
Run Code Online (Sandbox Code Playgroud)

angularjs

186
推荐指数
6
解决办法
35万
查看次数

JavaScript中几年,几个月,几天的两个日期之间的差异

我现在已经搜索了4个小时,并且没有找到解决方案来获取JavaScript中年,月和日的两个日期之间的差异,例如:2010年4月10日是3年,x个月和y天前.

有很多解决方案,但它们只提供日期或月份或年份的格式差异,或者它们不正确(意味着不处理一个月或闰年的实际天数等).这样做真的很难吗?

我看过:

在PHP中它很容易,但不幸的是我只能在该项目上使用客户端脚本.任何能够做到这一点的库或框架都可以.

以下是日期差异的预期输出列表:

//Expected output should be: "1 year, 5 months".
diffDate(new Date('2014-05-10'), new Date('2015-10-10'));

//Expected output should be: "1 year, 4 months, 29 days".
diffDate(new Date('2014-05-10'), new Date('2015-10-09'));

//Expected output should be: "1 year, 3 months, 30 days".
diffDate(new Date('2014-05-10'), new Date('2015-09-09'));

//Expected output should be: "9 months, 27 days".
diffDate(new Date('2014-05-10'), new Date('2015-03-09'));

//Expected output should be: "1 year, 9 months, 28 days".
diffDate(new Date('2014-05-10'), new Date('2016-03-09')); …
Run Code Online (Sandbox Code Playgroud)

javascript datediff date

41
推荐指数
10
解决办法
10万
查看次数

如何在Ruby中从平面数组创建直方图

如何创建整数数组的直方图?例如:

data = [0,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,7,8,9,9,10]
Run Code Online (Sandbox Code Playgroud)

我想基于有多少项有用于创建直方图0,1,2,等等.在Ruby中有一个简单的方法吗?

输出应该是两个数组.第一个数组应包含组(bin),第二个数组应包含出现次数(频率).

对于data上面给出的,我希望以下输出:

bins         # => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
frequencies  # => [1, 1, 5, 6, 4, 2, 3, 5, 1, 2, 1]
Run Code Online (Sandbox Code Playgroud)

ruby histogram

21
推荐指数
2
解决办法
1万
查看次数

移动后如何修复本地git仓库的路径?

移动后如何修复本地git仓库的路径?

previous local location: /C/website
new local location: /C/Projects/website
remote location: git@bitbucket.org:username/website.git
Run Code Online (Sandbox Code Playgroud)

我将我的git存储库从一个文件夹移动/website到另一个文件夹/projects/website,现在我收到一个错误:

user@Thinkpad /C/Projects/website (master)
$ git push
fatal: 'C:/website' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题,而无需重新克隆项目?我试过了:

$ git init
Reinitialized existing Git repository in c:/Projects/website/.git/
Run Code Online (Sandbox Code Playgroud)

它没有做任何事情,当我试图推动时,我又得到了完全相同的错误.

编辑:

我跑了:git config remote.origin.url C:/Projects/website.现在,当我在更改文件后提交时,我收到以下回复:

user@Thinkpad /C/Projects/website (master)
$ git commit -m "added something" …
Run Code Online (Sandbox Code Playgroud)

git move

15
推荐指数
1
解决办法
1万
查看次数

升级Mac OS X Yosemite后,Mysql无法启动(Mac OS 10.10)

升级到Mac OS Yosemite(10.10)后,我的Mysql将不再启动.相反,我得到了

MacBook-Pro:/ user$ sudo /usr/local/mysql/support-files/mysql.server start
Starting MySQL 
. ERROR! The server quit without updating PID file (/usr/local/mysql/data/wireless.ubc.ca.pid).
Run Code Online (Sandbox Code Playgroud)

我试图检查版本号,但我也得到以下错误

MacBook-Pro:/ user$ /usr/local/mysql/bin/mysql -v
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Run Code Online (Sandbox Code Playgroud)

我发现很多人在Yosemite安装后XAMPP 无法正常工作,而eclipse也无法正常工作.我看到很多人只是说重装.有没有什么办法解决这一问题?

mysql macos osx-yosemite

10
推荐指数
1
解决办法
2万
查看次数

如何使用JGit获取文件中的更改列表?

使用JGit,我希望尽可能获得提交文件中的更改列表git log --full-history -p -1 <hash-id>.

这可能吗?如果是这样,你怎么做?

我知道如何获取每个提交,并查看提交消息:

//Load repo
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(new File("/path/to/repo/.git")).setMustExist(true).build();
Git git = new Git(repo);
//get commits
Iterable<RevCommit> log = git.log().call();
for (RevCommit commit : log) {
    //Shows the hashid
    System.out.println("LogCommit: " + commit);
    //Shows only commit message
    String logMessage = commit.getFullMessage();
    System.out.println("LogMessage: " + logMessage);
}
git.close();
Run Code Online (Sandbox Code Playgroud)

是什么让我得到文件的变化?

例如我写道:

git log --full-history -p -1 8309c1262e1b7ffce8fc86efc1ae5777a4a96777
Run Code Online (Sandbox Code Playgroud)

回应是

commit 8309c1262e1b7ffce8fc86efc1ae5777a4a96777
Author: <redacted>
Date:   Thu Aug 4 12:15:23 2016 -0400 …
Run Code Online (Sandbox Code Playgroud)

java eclipse git jgit

10
推荐指数
2
解决办法
4417
查看次数

通知上的Android Catch事件(长按)

标准的通知短按会触发其中的PendingIntent.

有可能赶上其他事件吗?

要求是抓住长按.

android android-notifications

9
推荐指数
1
解决办法
2303
查看次数

单元测试ASP.net Page_Load

如何在ASP.net中为Page_Load函数创建单元测试?

我正在使用Visual Studio Unit测试框架构建工作.我想创建一个单元测试来检查网页的元素及其值.

我知道硒及其在单元测试中的能力.

这是测试WebPageControl.ascx.vb的网页:

   Public Class WebPageControl
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            TextBox.Visible = False
        End Sub
End Class
Run Code Online (Sandbox Code Playgroud)

这是单元测试WebPageControlTest.vb:

Public Class WebPageControlTest
    Public Sub PageLoadTest()

        Dim target As WebPageControl_Accessor = New WebPageControl_Accessor() 
        Assert.IsFAlse(target.TextBox.Visible)
    End Sub
End Class
Run Code Online (Sandbox Code Playgroud)

我这样做后仍然出错

Test method RechargeTest.WebPageControlTest.PageLoadTest threw exception: System.NullReferenceException: Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)

vb.net asp.net unit-testing

6
推荐指数
1
解决办法
2370
查看次数

使用AutoIt从iframe获取表单名称

我正在使用AutoIt自动填写网站上的表单.

但我在从网站获取表单名称时遇到问题.我查看HTML的来源并查找表单及其名称,但我仍然收到IEStatus_noMatch错误.

是否有更简单的方法来获取表单名称或如何找到它?

对于对象,我可能会遇到同样的问题.

$sUrl = "https://www.acgme.org/residentdatacollection/login.asp"
$oIE = _IEAttach($sUrl, "url")
If not isObj($oIE) Then
    $oIE = _IECreate()
    _IENavigate($oIE, $sUrl)
EndIf

; Get pointers to the login form and username and password fields
$o_form = _IEFormGetObjByName($oIE, "loginentry")
$o_login = _IEFormElementGetObjByName($o_form, "USERID")
$o_password = _IEFormElementGetObjByName($o_form, "PASSW")
Run Code Online (Sandbox Code Playgroud)

html internet-explorer autoit

6
推荐指数
1
解决办法
7471
查看次数

禁用地图滚动打开街道地图

如何在打开的地图中禁用鼠标交互或滚动iframe?我有以下内容,我放置了属性scrollwheel="false"是否有通过 css 的方法可以通过 css 禁用滚动或交互?

<iframe id= "mapsource" scrollwheel="false" src="http://www.openstreetmap.org/export/embed.html?bbox=-123.21233510971068%2C49.260691198361066%2C-123.18484783172607%2C49.27329289319553&amp;layer=mapquest&amp;marker=49.26699244809891%2C-123.19858074188232"></iframe>
Run Code Online (Sandbox Code Playgroud)

我愿意接受其他选项,例如使用 javascript 来禁用滚动?

html javascript css maps

6
推荐指数
2
解决办法
8799
查看次数