为什么我不能在服务中观看对象.我有一个简单的变量工作,但一个对象不起作用. http://plnkr.co/edit/S4b2g3baS7dwQt3t8XEK?p=preview
var app = angular.module('plunker', []);
app.service('test', ['$http', '$rootScope',
function ($http, $rootScope) {
var data = 0;
var obj = {
"data": 0
};
this.add = function(){
obj.data += 1;
console.log('data:', obj);
};
this.getData = function() { return obj; };
}]);
app.controller('TestController', ['$scope', '$rootScope', '$filter', 'test',
function($scope, $rootScope, $filter, test) {
//test controller
$scope.add = function(){
test.add();
};
$scope.test = test;
$scope.$watch('test.getData()', function(newVal){
console.log('data changes into: ', newVal)
});
}]);
Run Code Online (Sandbox Code Playgroud) 当我尝试迁移某些内容时,我收到此错误:
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command?
Command Cancelled!
Run Code Online (Sandbox Code Playgroud)
我正在运行没有Plesk 12的centOS6.6服务器无论如何都要弄清楚错误是什么或如何解决它?
谢谢
如何在javascript中停止间隔?
为什么间隔不停?
setInterval(alarm, 500);
window.clearInterval(alarm);
Run Code Online (Sandbox Code Playgroud)
还尝试过:
window.setInterval(alarm, 500);
window.clearInterval(alarm);
Run Code Online (Sandbox Code Playgroud)
总是同样的问题:(
仍然不起作用:
var switc = 1;
getValue();
function getValue (){
if(switc == 1){
var myTimer = window.setInterval(alarm, 500);
}
else if(switc == 0){
window.clearInterval(myTimer);
}
}
function alarm(){
console.log("test");
}
Run Code Online (Sandbox Code Playgroud) 我想使用函数addMenu和菜单,但我收到此错误:
Using $this when not in object context
Run Code Online (Sandbox Code Playgroud)
我做错什么了吗?还是有另一种方法来调用这些功能?
我的代码:
class Documentation {
protected $app;
protected $menu = [];
public function __construct(Application $app){
$this->app = $app;
$this->addMenu(["Hello world"]);
}
public static function addMenu($item){
$this->menu[] = $item;
}
public static function menu(){
return $this->menu;
}
}
Run Code Online (Sandbox Code Playgroud)