以下代码说明了该问题:
<!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) 我有一些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)
发生这种情况时,结果是一个空文件和一个不愉快的构建.任何想法为什么会这样?我应该做些什么呢?
无论我做什么,我似乎都无法完成这项工作。让我用一个非常简单的示例扩展来演示。这是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) 我正在尝试编写一个 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)