如何在angularjs指令的数据绑定值中添加双引号?

时间:2018-06-22 05:29:33

标签: angularjs

我正在使用angularjs指令,我想为通过angularjs模板中的数据绑定获取的值添加双引号。

我的代码是

template = '<div>'+
            '<a>'+'User name is ' + user.name  + '</a>'+
            '</div>' 

我需要如下输出 用户名是“ davit”

如何为davit名称添加双引号?

2 个答案:

答案 0 :(得分:1)

只需在单引号之前和之后添加双引号

class Dashboard extends Component { //Smart or Container Component
    state = {dashboard:{}}

    async componentWillMount() {
        try {
            const response = await apiService.fetchDashboardInfo()
            this.setState({dashboard:response.data.data});
        } catch (error) {
            console.log("fetch dashboard info",error)
        }
    }

    render() {
        if(Object.keys(this.state.dashboard).length > 0) {
            return <DashboardDetail dashboard={this.state.dashboard}/>
        }
        return (
            <div>
                Loading
            </div>
        );
    }
}

const DashboardDetail = (props) =>{ //Stateless Component
    return(
        <div className="main-content">
            <div className="main-content-inner">
                <Field color={'red'} field={"Votes"} value={props.dashboard.total_vote} />
            </div>
        </div>
    )
}

const Field = (props) => { //Another Stateless Component
    return(
            <div className="infobox-data">
                <div className="infobox-content">{props.field}</div>
            </div>
    )
}

export default Dashboard;

答案 1 :(得分:0)

尝试一下:-

0.49999999999999998999823495882122159628124791197478771209716796875
0.5
0.5