考虑一下:
#ifndef GUARD_H
#define GUARD_H
...
#endif GUARD_H
Run Code Online (Sandbox Code Playgroud)
而不是:
#ifndef GUARD_H
#define GUARD_H
...
#endif // GUARD_H
Run Code Online (Sandbox Code Playgroud)
我常常看到#endif一个"标识符"已注释掉,但没有评论它仍然有效.
一切都是在#endif悔改之后还是......?
我已经搜索了互联网试图弄清楚为什么专有的AngularJS验证在使用jQuery.Select2和ui-select2指令时不起作用- 这是一个错误?
编辑:好的我发现它只是标记输入正在发生,我的选择下拉菜单和文本输入工作正常.
这是小提琴 http://jsfiddle.net/whiteb0x/ftEHu/
HTML:
<form name="myForm" ng-controller="Ctrl">
userType: <input ui-select2="version1" class="input-xlarge" type="hidden" name="input" ng-model="userType" required>
<span class="error" ng-show="myForm.input.$error.required">Required</span><br>
<tt>userType = {{userType}}</tt><br>
<tt>myForm.input.$valid = {{myForm.input.$valid}} wtf???????!!!</tt><br>
<tt>myForm.input.$error = {{myForm.input.$error}} huh????</tt><br>
<tt>myForm.$valid = {{myForm.$valid}} | please hand me a gun :)</tt><br>
<tt>myForm.$error.REQUIRED = {{!!myForm.$error.REQUIRED}}</tt><br>
</form>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var app = angular.module('myApp', ['ui.directives']);
function Ctrl($scope) {
$scope.userType = '';
$scope.version1 = {
tags : null
};
}
Run Code Online (Sandbox Code Playgroud) 这只是关于Angular指令的一般问题.为什么angular选择具有返回对象的函数而不仅仅直接将对象列为第二个参数?
换句话说,为什么它看起来像这样:
app.directive('helloWorld', function() {
return {
restrict: 'AE',
replace: 'true',
template: '<h3>Hello World!!</h3>'
};
});
Run Code Online (Sandbox Code Playgroud)
而不是这个:
app.directive('helloWorld',{
restrict: 'AE',
replace: 'true',
template: '<h3>Hello World!!</h3>'
});
Run Code Online (Sandbox Code Playgroud) 我是角度新手,所以这可能不是最好的方法。随着我了解更多,我可能会重做大部分已经做过的事情。
我正在使用 url 路由,ngRoute它工作得很好。在其中一个页面中,我有许多 ng-include 模板 - 再次,一切都很好。
在其中一个ng-include模板中,我使用两个directives来显示模板。
<provider-search providers="practiceData.providers" states="ref.states" specialties="ref.specialties" status="updateSearchStatus" ng-show="searchStatus == 1"/>
<search-list status="updateSearchStatus" addp="addProvider" providers="searchResults" ng-if="searchStatus == 2" />
Run Code Online (Sandbox Code Playgroud)
每个指令都使用独立的作用域和控制器。问题是只有第一个指令有效。如果我切换顺序,则第二个指令(现在如果是第一个位置)将起作用。简而言之,只有首先列出的指令才有效。
任何帮助表示赞赏。
我知道你可能会将此标记为重复,但兄弟主题都没有解决我的问题,所以这是我简单的日期倒计时指令:
class Clock {
constructor() {
this.restrict = 'AC';
this.replace = true;
this.template = require('./templates/clock.tpl.html');
this.scope = {};
}
link(scope, elem, attrs, $interval) {
let end = new Date('05/05/2017 9:00 AM');
let _second = 1000;
let _minute = _second * 60;
let _hour = _minute * 60;
let _day = _hour * 24;
scope.showRemaining = () => {
let now = new Date();
let distance = end - now;
let days = Math.floor(distance / _day);
let hours = Math.floor((distance % …Run Code Online (Sandbox Code Playgroud) 我可以编写代码来将变量设置为true或false,具体取决于我按下的按钮吗?见下面的例子.
如果没有,还有其他方法可以达到类似的效果吗?我已经使用指令标记了不同模式的代码,并且只希望开发人员可以选择切换模式,但现在我希望为用户提供在模式之间切换的选项.模式的选择仅在程序开始时给出,并且不允许用户切换模式.要切换模式,他只能重新启动程序.
如果不能使用指令,我可以使用哪种方法最快?(注意:声明都在解决方案的周围)
在我希望实现的pseduocode中:
void button_click(...){
if(!CONDITION)
CONDITION = true;
else
CONDITION = false;
}
...
#if CONDITION
//mode X with addtional steps
#endif
Run Code Online (Sandbox Code Playgroud) 我可以创建两个指令.在这种情况下,一个名为zMonthSelect,另一个名为zTest,引用zMonthSelect.如果它们是嵌套的,Angular似乎不喜欢它们.这是为什么?我该怎么办才能修复它?
这是代码:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
});
app.directive('zMonthSelect', function () {
return {
restrict: 'E',
priority: 1000,
scope: {
month: '=month'
},
template: '<select ng-model="month">' +
'<option value="1">Jan</option>' +
'<option value="2">Feb</option>' +
'<option value="3">Mar</option>' +
'<option value="4">Apr</option>' +
'<option value="5">May</option>' +
'<option value="6">Jun</option>' +
'<option value="7">Jul</option>' +
'<option value="8">Aug</option>' +
'<option value="9">Sep</option>' +
'<option value="10">Oct</option>' +
'<option value="11">Nov</option>' +
'<option value="12">Dec</option>' +
'</select>',
controller: function($scope) {
}
};
}); …Run Code Online (Sandbox Code Playgroud) 我一直在试图写一个#define类似函数的宏,但是我被卡住了.这是我正在使用的示例:
#include <iostream>
#define pMAKE(x,y,z,dest)\
(dest).(x) = (x);\
(dest).(y) = (y);\
(dest).(z) = (z);
struct pt {
double x, y, z;
};
int main() {
pt p;
pMAKE(0,1,2,p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
A.cpp: In function ‘int main()’:
A.cpp:13: error: expected unqualified-id before ‘(’ token
A.cpp:13: error: expected unqualified-id before ‘(’ token
A.cpp:13: error: expected unqualified-id before ‘(’ token
Run Code Online (Sandbox Code Playgroud)
这些错误意味着什么,为什么我会得到它们?我设法得到以下工作方式,但我真的很幸运,我真的不明白发生了什么.
#define pMAKE(X,Y,Z,dest)\
dest.x = (X);\
dest.y = (Y);\
dest.z = (Z);
Run Code Online (Sandbox Code Playgroud)
我感谢你的每一点帮助!
有没有办法在不使用C代码中的#字符的情况下使用预处理程序指令?我们可以通过使用它的ASCII等等来以某种方式回显哈希字符吗?
例如:
1可以通过'SOH'在.c源文件中使用来回显.是否有类似的黑客'#'?
我正在使用角度来显示Youtube的iframe.为了,我使用$ sce来信任外部URL,但我有一个我无法解决的错误...也许有人可以向我解释
Controller.js
.controller('DetailsCtrl', ['$scope', '$routeParams', '$http',
function($scope, $routeParams, $http, $sce) {
$scope.loading = true;
$scope.url = $sce.trustAsResourceUrl('//www.youtube.com/embed/4wOoLLDXbDY');
$http.get('projects/' + $routeParams.projectId + '.json').success(function(data) {
$scope.project = data;
$scope.loading = false;
});
}]);
Run Code Online (Sandbox Code Playgroud)
Details.html
<iframe width="560" height="315" ng-src"{{url}}" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
控制台出错
TypeError: Cannot call method 'trustAsResourceUrl' of undefined
at new <anonymous> (http://localhost:9000/scripts/controllers/details.js:22:25)
at invoke (http://localhost:9000/bower_components/angular/angular.js:3869:17)
at Object.instantiate (http://localhost:9000/bower_components/angular/angular.js:3880:23)
at http://localhost:9000/bower_components/angular/angular.js:7134:28
at link (http://localhost:9000/bower_components/angular-route/angular-route.js:913:26)
at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:6579:13)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:5986:15)
at publicLinkFn (http://localhost:9000/bower_components/angular/angular.js:5891:30)
at boundTranscludeFn (http://localhost:9000/bower_components/angular/angular.js:6005:21)
at controllersBoundTransclude (http://localhost:9000/bower_components/angular/angular.js:6600:18) <div ng-view="" class="ng-scope">
Run Code Online (Sandbox Code Playgroud)