私のhtmlヘッドには配列があります。これは、Django テンプレートでレンダリングして便利だからです。
<script type="text/javascript"> foo = ["Python", "Marketing", "Start-ups", "business"]
</script>
私directive.js
が持っているディレクティブのコードがある私の中に:
$scope.foo = foo; // so it takes the data and the global value from the template
$scope.foo.push('wrong'); // let's add a value
$scope.reset = function(){
$scope.foo = foo; // rebind with the global value
console.log(foo)
}
をログに記録するfoo
と、["Python", "Marketing", "Start-ups", "business", "wrong"]
.
を省略して同じコードを試してみました$scope.foo = foo;
。配列を使用する場合reset()
、正しい配列["Python", "Marketing", "Start-ups", "business"]
です。
それはどんな魔術ですか?