我在angularjs中创建了一个自定义指令:
directives.directive('myTop',function($compile) {
return {
restrict: 'E',
templateUrl: 'views/header.html',
}
})
Run Code Online (Sandbox Code Playgroud)
指令的代码:
<div class="my-header">
<button ng-click="alert('x')" class="fa fa-chevron-left"></button>
<h1>SpeakZ</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
出于某种原因,ng-click不会触发.
我在互联网上搜索,发现编译/链接是这个问题的解决方案,但我似乎无法达成一个有效的解决方案.
我不是在使用jquery ..
我一直在编写反应组件与typescript,遵循官方打字稿文档中的说明:
https://www.typescriptlang.org/docs/handbook/react-&-webpack.html
我正在使用V8Js php扩展来在服务器端渲染React,但似乎我缺乏对使用V8Js的正确方法的理解.
这是我的反应应用程序:(客户端呈现)
http://codepen.io/MasterScripter/pen/xqRZQO
我试着在side-server上渲染:
<?php
$v8 = new V8Js();
$react = [];
// stubs, react
$react[] = "var console = {warn: function(){}, error: print}";
$react[] = "var global = {}";
$react[] = file_get_contents('./dist/react.js');
$react[] = "var React = global.React";
$react[] = file_get_contents('./dist/bundle.js');
$data = [
'value' => 1,
'onClick' => 'function'
];
$react[] = sprintf(
"React.renderComponentToString(Square({data: %s}), print)",
json_encode($data));
$react = implode(";", $react);
try {
$v8->executeString($react);
} catch(V8JsException $e) {
echo "
File: {$e->getJsFileName()} \n
Line Number: …Run Code Online (Sandbox Code Playgroud) 我正在使用没有jQuery的angularjs,并尝试创建滚动事件侦听器。
尝试了这种方法:
$rootScope.$watch(function() {
return $window.scrollY;
}, function(n,o) {
console.log('scroll');
});
Run Code Online (Sandbox Code Playgroud)
但这没用..
我设法通过使用此技术来创建调整大小的侦听器来实现此目标:
$rootScope.$watch(function() { // Listens to window size change
return $window.innerWidth;
}, function(n, o) {
console.log('resize');
});
Run Code Online (Sandbox Code Playgroud)
有没有适当的方法来创建纯angularjs滚动侦听器?