小编dan*_*hel的帖子

AngularJS ngModel在ui-bootstrap tabset中不起作用

以下代码说明了该问题:

<!DOCTYPE html>
<html ng-app="plunker">
  <head>
    <title>AngularJS Plunker</title>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
    <script src="https://code.angularjs.org/1.3.6/angular.js"></script>
    <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.min.js"></script>
    <script>
angular.module('plunker', ['ui.bootstrap'])
.controller('MainCtrl', function($scope) {
  $scope.changes = 0;
  $scope.updateValueInScope = function () {
    $scope.valueInScope = $scope.value;
    $scope.changes++;
  }
});
    </script>
  </head>

  <body ng-controller="MainCtrl">
    <tabset>
      <tab heading="Tab A">
        <div class="panel">
          <input type="text" ng-model="value" ng-change="updateValueInScope()" />
          <br />
          <tt>value: {{value}}</tt><br />
          <tt>valueInScope: {{valueInScope}}</tt><br />
          <tt>changes: {{changes}}</tt>
        </div>
      </tab>
    </tabset>
    <input type="text" ng-model="value" ng-change="updateValueInScope()" />
    <br />
    <tt>value: {{value}}</tt><br />
    <tt>valueInScope: {{valueInScope}}</tt><br />
    <tt>changes: {{changes}}</tt>
  </body> …
Run Code Online (Sandbox Code Playgroud)

javascript twitter-bootstrap angularjs angular-ui-bootstrap

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

Set-Content偶尔失败,"Stream不可读"

我有一些PowerShell脚本在构建之前准备文件.其中一个操作是替换文件中的某些文本.我使用以下简单函数来实现此目的:

function ReplaceInFile {
    Param(
        [string]$file,
        [string]$searchFor,
        [string]$replaceWith
    )

    Write-Host "- Replacing '$searchFor' with '$replaceWith' in $file"

    (Get-Content $file) |
    Foreach-Object { $_ -replace "$searchFor", "$replaceWith" } |
    Set-Content $file
}
Run Code Online (Sandbox Code Playgroud)

此函数偶尔会因错误而失败:

Set-Content : Stream was not readable.
At D:\Workspace\powershell\ReplaceInFile.ps1:27 char:5
+     Set-Content $file
+     ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (D:\Workspace\p...AssemblyInfo.cs:String) [Set-Content], ArgumentException
    + FullyQualifiedErrorId : GetContentWriterArgumentError,Microsoft.PowerShell.Commands.SetContentCommand
Run Code Online (Sandbox Code Playgroud)

发生这种情况时,结果是一个空文件和一个不愉快的构建.任何想法为什么会这样?我应该做些什么呢?

powershell

8
推荐指数
3
解决办法
1455
查看次数

如何让 content_scripts 在 Chrome 扩展程序中的 file:/// URL 中执行

无论我做什么,我似乎都无法完成这项工作。让我用一个非常简单的示例扩展来演示。这是manifest.json

{
  "manifest_version": 2,

  "name": "Sample Of Content Script",
  "description": "Changes the background of a page pink",
  "version": "1.0",

  "content_scripts": [
    {
      "matches": [ "<all_urls>" ],
      "js": [ "changer.js" ]
    }
  ],

  "permissions": [
    "webNavigation"
  ],

  "background": {
    "scripts": [ "background.js" ]
  }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我的content_scripts条目匹配all_urls,它(根据Google 文档)应该匹配file:///URL。

background.js

(function (chrome) {
    'use strict';

    chrome.webNavigation.onCompleted.addListener(function (details) {
        chrome.tabs.sendMessage(details.tabId, {
            action: 'changeBackground',
            color: 'pink'
        });
    });

})(chrome);
Run Code Online (Sandbox Code Playgroud)

changer.js(内容脚本):

(function …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome google-chrome-extension

7
推荐指数
1
解决办法
1384
查看次数

为什么我的 Chrome 扩展程序中从未收到 onCreated 事件的选项卡会收到 webNavigation.onCompleted 事件?

我正在尝试编写一个 Chrome 扩展程序,以密切跟踪打开的各个选项卡。不过,似乎新标签不断凭空出现。这里发生了什么?

这是一个非常简单的背景页面,说明了我正在谈论的内容:

(function () {
    'use strict';

    var tabKeeper = {};

    function logError(tabId) {
        if (!tabKeeper[tabId]) {
            console.log('Tab ' + tabId + ' not found!');
            console.log(JSON.stringify(tabKeeper));
            tabKeeper[tabId] = true;
        }
    }

    chrome.tabs.onCreated.addListener((tab) => {
        console.log('Tab created: ' + tab.id);
        tabKeeper[tab.id] = true;
    });

    chrome.webNavigation.onCompleted.addListener((details) => {
        console.log('Navigation complete: ' + details.tabId);
        logError(details.tabId);
    });

    chrome.tabs.query({}, (tabs) => {
        if (!tabs) { return; }
        tabs.forEach((tab) => {
            console.log('Tab found at startup: ' + tab.id);
            tabKeeper[tab.id] = true;
        });
    });

})(); …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome google-chrome-extension

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