这是关于ng-init
的角度文档。
ngInit指令允许您评估当前范围中的表达式。
但是,如果我将ng-init
与自定义指令一起使用,并且该指令使用不同的范围,则<body ng-app="transcludeScope" ng-init="test='test'">
<div truescope ng-init="test2='test2'">Transcluded:<p>test: {{test}}</p><p>test2: {{test2}}</p><p>test3: {{test3}}</p></div>
<hr>
<div isolatescope ng-init="test3='test3'">Transcluded:<p>test: {{test}}</p><p>test2: {{test2}}</p><p>test3: {{test3}}</p></div>
</div>
</body>
angular.module('transcludeScope', [])
.directive('truescope', function() {
return {
transclude: true,
scope: true,
template: "<p>test: {{test}}</p><p>test2: {{test2}}</p><div ng-transclude></div>"
}
})
.directive('isolatescope', function() {
return {
transclude: true,
scope: {},
template: "<p>test: {{test}}</p><p>test3: {{test3}}</p><div ng-transclude></div>"
}
});
的变量将具有不同的范围。
test2
从结果来看,test3
仅在指令内可用,而 // Program uses wave data to calcuulate steepness and average steepness for the year
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
using namespace std;
struct DNAnt{
int adenine, cytosine, guanine, thymine;
string strand;
char allDNA[100][80];
};
void data2DNA(int * , int * , int * , int * , string);
void countDNA(int * , int * , int * , int * , string , bool *);
void DNAtoRNA(char );
int main()
{
DNAnt DNA;
data2DNA(&DNA.adenine, &DNA.cytosine, &DNA.guanine, &DNA.thymine, DNA.strand);
ifstream inputFile;
inputFile.open("C:\\Users\\mjass_000\\Desktop\\DNA.txt");
for(int y=0; y<80; y++){ //inputting information into array
for(int x=0; x<100; x++){ //-----
inputFile >> DNA.allDNA[x][y]; //-----
} //-----
} //-----
DNAtoRNA(DNA.allDNA[100][80]);
inputFile.close();
cin.get();
return 0;
}
void data2DNA(int *adenine, int *cytosine, int *guanine, int *thymine, string strand){
ifstream inputFile;
inputFile.open("C:\\Users\\mjass_000\\Desktop\\data.txt");
ofstream outputFile;
outputFile.open("C:\\Users\\mjass_000\\Desktop\\DNA.txt");
int number, numA=0, numC=0, numG=0, numT=0, count=0;
bool end=false;
while (inputFile >> number){
if(number==1){
strand="A";
outputFile << strand; //outputting to file
countDNA(&numA, &numC, &numG, &numT, strand, &end);
count++;
}else if(number==2){
strand="C";
outputFile << strand;
countDNA(&numA, &numC, &numG, &numT, strand, &end);
count++;
}else if(number==3){
strand="G";
outputFile << strand;
countDNA(&numA, &numC, &numG, &numT, strand, &end);
count++;
}else if(number==4){
strand="T";
outputFile << strand;
countDNA(&numA, &numC, &numG, &numT, strand, &end);
count++;
}
if(count==10000){ //if it is the last number
end=true;
*adenine=numA;
*cytosine=numC;
*guanine=numG;
*thymine=numT;
}
}
outputFile.close();
inputFile.close();
return;
}
void countDNA(int *numA, int *numC, int *numG,int *numT, string strand, bool *end){
if(strand=="A"){
*numA+=1;
}else if(strand=="C"){
*numC+=1;
}else if(strand=="G"){
*numG+=1;
}else if(strand=="T"){
*numT+=1;
}
return;
}
void DNAtoRNA(char allDNA[100][80]){
ofstream outputFile;
outputFile.open("C:\\Users\\mjass_000\\Desktop\\RNA.txt");
int totalT=0;
for(int y=0; y<80; y++){
for(int x=0; x<100; x++){
if(allDNA[x][y]=='T'){
totalT++;
}
}
if(totalT>25){ //if there are more than 25 T's
for(int x=0; x<100; x++){ //-----
if(allDNA[x][y]=='T'){ //-----
outputFile << "U"; //-----
}else{ //-----
outputFile << allDNA[x][y]; //-----
} //-----
} //-----
}else{ //-----
for(int x=0; x<100; x++){
outputFile << allDNA[x][y];
}
}
totalT=0;
outputFile << endl;
}
outputFile.close();
return;
}
可用于整个应用。
任何人都可以解释他们的行为吗?谢谢: - )