我在codepen中使用以下代码并面临此问题,对于conctact我收到以下错误
为什么它会给出错误的联系而不是名字?
我怎么解决这个问题?
angular.js:13550 ReferenceError: contact is not defined
at new <anonymous> (pen.js:8)
at Object.invoke (angular.js:4665)
at R.instance (angular.js:10115)
at n (angular.js:9033)
at g (angular.js:8397)
at g (angular.js:8400)
at angular.js:8277
at angular.js:1751
at n.$eval (angular.js:17229)
at n.$apply (angular.js:17329)
Run Code Online (Sandbox Code Playgroud)
这是js文件
var app = angular.module("crud", []);
app.controller("ctrl", ['$scope', function($scope) {
$scope.data = [3, 4, 5, 34, 34];
debugger;
$scope.name = name;
$scope.contact = contact;
$scope.obj = {
name: $scope.name,
contact: $scope.contact
};
console.log($scope.obj);
}]);
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的HTML文件.
<body ng-app="crud">
<div ng-controller="ctrl">
<div>
<table>
<tr …Run Code Online (Sandbox Code Playgroud) 这是我正在使用的代码,不明白为什么ng-bind和和的输出有差异{{}}.
angular.module('Test', []);Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="Test">
<input type="text" ng-model="foo.bar" />
<input type="text" ng-model="foo.baz" />
<p ng-bind="foo"></p>
<p>{{ foo }}</p>
</div>Run Code Online (Sandbox Code Playgroud)
这是我得到的输出
//for ng-bind
[object Object]
//for {{}}
{"foo":"ankur","bar":"23"}
Run Code Online (Sandbox Code Playgroud) {{}}工作正常,但ng-model不在同一个地方.
我使用以下html-
<body ng-app="crud">
Gray input fields will not be visible.
<div ng-controller="ctrl">
<input type="text" value="sdf" ng-model="asdf"/>
<h1 ng-model="asdf"></h1> <!-- this doesn't work-->
<h1>{{asdf}}</h1> <!-- this work-->
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
asdf是在这个js应用程序中定义的
var app = angular.module("crud", []);
app.controller("ctrl", ['$scope', function($scope) {
$scope.asdf="ankur";
}]);
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么会这样吗?
最近,我看到了两篇关于 mixin 的文章。这让我在哪个比另一个更好之间感到困惑。
第一个来自mdn
var calculatorMixin = Base => class extends Base {
calc() { }
};
var randomizerMixin = Base => class extends Base {
randomize() { }
};
class Foo { }
class Bar extends calculatorMixin(randomizerMixin(Foo)) { }Run Code Online (Sandbox Code Playgroud)
来自https://javascript.info/mixins 的第二个
let sayMixin = {
say(phrase) {
alert(phrase);
}
};
let sayHiMixin = {
__proto__: sayMixin, // (or we could use Object.create to set the prototype here)
sayHi() {
// call parent method
super.say(`Hello ${this.name}`);
}, …Run Code Online (Sandbox Code Playgroud)"ange134".match(/\d+/) // result => 134
"ange134".match(/\d*/) // result => "" //expected 134
Run Code Online (Sandbox Code Playgroud)
在上述情况下,+表现得很好,因为贪婪.
但为什么/\d*/不回归同样的事情呢?
我无法调用 postMessage,以防我在 srcdoc 属性中传递 html
如果没有 sandbox = "allow-scripts"
,它会给出以下错误
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://example.com') does not match the recipient window's origin ('https://example.com:444').
与 sandbox = "allow-scripts"
,它给出以下错误
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://example.com') does not match the recipient window's origin ('null').
我想在没有沙箱属性的情况下调用postMessage,可以吗?
如果没有,还有其他办法吗?
这是我在控制台中运行的代码.
// Parameterless arrow functions that are visually easier to parse
setTimeout( () => {
console.log('I happen sooner');
setTimeout( () => {
// deeper code
console.log('I happen later');
}, 1);
}, 1);
Run Code Online (Sandbox Code Playgroud)
这样的记录是这样的
32
I happen sooner
I happen later
Run Code Online (Sandbox Code Playgroud)
我不明白这是什么意思,每次增加2,我运行相同的代码.
javascript ×7
angularjs ×3
html ×3
composition ×1
iframe ×1
inheritance ×1
mixins ×1
pycharm ×1
python ×1
regex ×1
settimeout ×1